Flaggify — Create flags of countries and subdivisions (Bash package)
Below you find the latest version of (1) the package's README and (2) its main source file.
You may also want to read:
For the git repository and issue tracker, see the project's page on sr.ht.
For more packages, see Software.
Overview
Flaggify can convert:
- from two-letter territory code to territory flag
- from subdivision code to subdivision flag
A territory code can be anything from ISO 3166-1 alpha-2.
Subdivision code can be anything from ISO 3166-2.
A territory is typically a "country", with some exceptions (e.g. EU → 🇪🇺).
Your system needs a font that can display flag emojis. Then:
- Flags of all territories are usually available.
- As for subdivisions:
- England (🏴), Scotland (🏴), and Wales (🏴) are usually available.
- Beyond that, it'll depend on the font.
- England (🏴), Scotland (🏴), and Wales (🏴) are usually available.
Usage
For complete usage, run flaggify h.
Here are a few examples.
Replace in string
With r, find territory codes in a string and convert them to flags:
echo "The flag of Canada (CA) is widely known." | flaggify r flaggify r <<< "She thinks GB-WLS's flag looks nicer than GB-ENG's." flaggify r "Flags of CH and VA are 1:1, and NP's isn't rectangular."
⇒
The flag of Canada (🇨🇦) is widely known. She thinks 🏴's flag looks nicer than 🏴's. Flags of 🇨🇭 and 🇻🇦 are 1:1, and 🇳🇵's isn't rectangular.
Installation
See my page Software for the most up-to-date instructions on how to download and install my packages.
Dependencies: You'll want to have some font capable of displaying emoji flags.
Disclaimer
This package doesn't take or endorse any position on territorial claims, nor on flag designs, nor on any such disputes.
All this package does is:
- take your input query;
- apply functions to it;
- and serve you the converted output.
The applied functions simply follow standard ways to produce emoji flags.
Flag designs themselves are supplied by your emoji font. So if a flag you wanted is missing or seems inaccurate, and yet you'd like to see that corrected, then consider sending a bug report to the font designers.
Contributing
See my page Software for information about how to contribute to my packages.
License
This project follows the REUSE Specification (FAQ), which in turn is built upon SPDX.
Therefore, license and copyright information can be found in:
- each file's comment header, or
- an adjacent file of the same name with the additional extension
.license, or - the
.reuse/dep5file
The full text of the licenses can be found in the LICENSES subdirectory.
flaggify
Contents
#!/usr/bin/env bash # Flaggify --- Create flags of countries and subdivisions # SPDX-FileCopyrightText: © flandrew <https://flandrew.srht.site/listful> # SPDX-License-Identifier: GPL-3.0-or-later #---------------------# # Author: flandrew # # Created: 2024-04-24 # # Updated: 2025-10-31 # #---------------------# # Version: 0.2.0 # #---------------------# ### Commentary # # You'll want to have some font capable of displaying emoji flags. # ############################################################################# ### Code # REPLACE in string declare -a F F=(GB-ENG 🏴 GB-SCT 🏴 GB-WLS 🏴 AC 🇦🇨 AD 🇦🇩 AE 🇦🇪 AF 🇦🇫 AG 🇦🇬 AI 🇦🇮 AL 🇦🇱 AM 🇦🇲 AO 🇦🇴 AQ 🇦🇶 AR 🇦🇷 AS 🇦🇸 AT 🇦🇹 AU 🇦🇺 AW 🇦🇼 AX 🇦🇽 AZ 🇦🇿 BA 🇧🇦 BB 🇧🇧 BD 🇧🇩 BE 🇧🇪 BF 🇧🇫 BG 🇧🇬 BH 🇧🇭 BI 🇧🇮 BJ 🇧🇯 BL 🇧🇱 BM 🇧🇲 BN 🇧🇳 BO 🇧🇴 BQ 🇧🇶 BR 🇧🇷 BS 🇧🇸 BT 🇧🇹 BV 🇧🇻 BW 🇧🇼 BY 🇧🇾 BZ 🇧🇿 CA 🇨🇦 CC 🇨🇨 CD 🇨🇩 CF 🇨🇫 CG 🇨🇬 CH 🇨🇭 CI 🇨🇮 CK 🇨🇰 CL 🇨🇱 CM 🇨🇲 CN 🇨🇳 CO 🇨🇴 CP 🇨🇵 CR 🇨🇷 CU 🇨🇺 CV 🇨🇻 CW 🇨🇼 CX 🇨🇽 CY 🇨🇾 CZ 🇨🇿 DE 🇩🇪 DG 🇩🇬 DJ 🇩🇯 DK 🇩🇰 DM 🇩🇲 DO 🇩🇴 DZ 🇩🇿 EA 🇪🇦 EC 🇪🇨 EE 🇪🇪 EG 🇪🇬 EH 🇪🇭 ER 🇪🇷 ES 🇪🇸 ET 🇪🇹 EU 🇪🇺 FI 🇫🇮 FJ 🇫🇯 FK 🇫🇰 FM 🇫🇲 FO 🇫🇴 FR 🇫🇷 GA 🇬🇦 GB 🇬🇧 GD 🇬🇩 GE 🇬🇪 GF 🇬🇫 GG 🇬🇬 GH 🇬🇭 GI 🇬🇮 GL 🇬🇱 GM 🇬🇲 GN 🇬🇳 GP 🇬🇵 GQ 🇬🇶 GR 🇬🇷 GS 🇬🇸 GT 🇬🇹 GU 🇬🇺 GW 🇬🇼 GY 🇬🇾 HK 🇭🇰 HM 🇭🇲 HN 🇭🇳 HR 🇭🇷 HT 🇭🇹 HU 🇭🇺 IC 🇮🇨 ID 🇮🇩 IE 🇮🇪 IL 🇮🇱 IM 🇮🇲 IN 🇮🇳 IO 🇮🇴 IQ 🇮🇶 IR 🇮🇷 IS 🇮🇸 IT 🇮🇹 JE 🇯🇪 JM 🇯🇲 JO 🇯🇴 JP 🇯🇵 KE 🇰🇪 KG 🇰🇬 KH 🇰🇭 KI 🇰🇮 KM 🇰🇲 KN 🇰🇳 KP 🇰🇵 KR 🇰🇷 KW 🇰🇼 KY 🇰🇾 KZ 🇰🇿 LA 🇱🇦 LB 🇱🇧 LC 🇱🇨 LI 🇱🇮 LK 🇱🇰 LR 🇱🇷 LS 🇱🇸 LT 🇱🇹 LU 🇱🇺 LV 🇱🇻 LY 🇱🇾 MA 🇲🇦 MC 🇲🇨 MD 🇲🇩 ME 🇲🇪 MF 🇲🇫 MG 🇲🇬 MH 🇲🇭 MK 🇲🇰 ML 🇲🇱 MM 🇲🇲 MN 🇲🇳 MO 🇲🇴 MP 🇲🇵 MQ 🇲🇶 MR 🇲🇷 MS 🇲🇸 MT 🇲🇹 MU 🇲🇺 MV 🇲🇻 MW 🇲🇼 MX 🇲🇽 MY 🇲🇾 MZ 🇲🇿 NA 🇳🇦 NC 🇳🇨 NE 🇳🇪 NF 🇳🇫 NG 🇳🇬 NI 🇳🇮 NL 🇳🇱 NO 🇳🇴 NP 🇳🇵 NR 🇳🇷 NU 🇳🇺 NZ 🇳🇿 OM 🇴🇲 PA 🇵🇦 PE 🇵🇪 PF 🇵🇫 PG 🇵🇬 PH 🇵🇭 PK 🇵🇰 PL 🇵🇱 PM 🇵🇲 PN 🇵🇳 PR 🇵🇷 PS 🇵🇸 PT 🇵🇹 PW 🇵🇼 PY 🇵🇾 QA 🇶🇦 RE 🇷🇪 RO 🇷🇴 RS 🇷🇸 RU 🇷🇺 RW 🇷🇼 SA 🇸🇦 SB 🇸🇧 SC 🇸🇨 SD 🇸🇩 SE 🇸🇪 SG 🇸🇬 SH 🇸🇭 SI 🇸🇮 SJ 🇸🇯 SK 🇸🇰 SL 🇸🇱 SM 🇸🇲 SN 🇸🇳 SO 🇸🇴 SR 🇸🇷 SS 🇸🇸 ST 🇸🇹 SV 🇸🇻 SX 🇸🇽 SY 🇸🇾 SZ 🇸🇿 TA 🇹🇦 TC 🇹🇨 TD 🇹🇩 TF 🇹🇫 TG 🇹🇬 TH 🇹🇭 TJ 🇹🇯 TK 🇹🇰 TL 🇹🇱 TM 🇹🇲 TN 🇹🇳 TO 🇹🇴 TR 🇹🇷 TT 🇹🇹 TV 🇹🇻 TW 🇹🇼 TZ 🇹🇿 UA 🇺🇦 UG 🇺🇬 UM 🇺🇲 UN 🇺🇳 US 🇺🇸 UY 🇺🇾 UZ 🇺🇿 VA 🇻🇦 VC 🇻🇨 VE 🇻🇪 VG 🇻🇬 VI 🇻🇮 VN 🇻🇳 VU 🇻🇺 WF 🇼🇫 WS 🇼🇸 XK 🇽🇰 YE 🇾🇪 YT 🇾🇹 ZA 🇿🇦 ZM 🇿🇲 ZW 🇿🇼) # Replace with flags all code matches in string — by looking up array above. sed-expr() { printf 's/\\b%s\\b/%s/g;' "${F[@]}" ;} f-string() { sed -E "$(sed-expr)" <<< "$1" ;} ############################################################################# # TERRITORY conversion # Convert every letter (assumed upcase) to corresponding regional indicator. # This happens directly — no lookups. Pairs become flags (whenever existing). f-territ() while read -N1 -r c do : "$(printf "$c" | od -An -t x1)" : "$(printf "%X" "$((0xa5 + 0x${_// }))")" printf "\U1F1$_" done < <(printf "$1") ############################################################################# # SUBDIVISION conversion # Downcase and convert every letter to corresponding tag letter. # This happens directly — no lookups. taggify() while read -N1 -r c do : "$(printf "$c" | od -An -t x1)" printf "\UE00${_// }" done < <(printf "${1,,}" | tr -d -) # Then wrap it with waving black flag and cancel flag. f-subdiv() { printf "\U1F3F4$(taggify "$1")\UE007F" ;} ############################################################################# usage() { local p="$(basename "${BASH_SOURCE[0]}")" less <<EOU NAME $p --- Create flags of countries and subdivisions SYNOPSIS $p r [STRING] $p t [STRING] $p s [STRING] If STRING is not passed, read from stdin. DESCRIPTION The three operations above are: "replace", "territory", and "subdivision". - REPLACE looks for pairs of uppercase letters in a string and, assuming they refer to country codes, replace them with the corresponding flags if the countries exist: we look that up in an array. It also accepts England, Scotland, and Wales. - TERRITORY directly converts every letter (which must be upcased) to its corresponding regional indicator. Each pair of regional indicators is rendered as a flag whenever the corresponding territory exists. A territory is typically a "country", with some exceptions (e.g. EU → 🇪🇺). No newlines are added to the end of the result. - SUBDIVISION directly converts every letter to its corresponding lowercase tag letter. This is then wrapped with a "waving black flag" and a "cancel tag". All this is displayed as subdivision flag, provided you have a font that supports it. No newlines are added to the end of the result. REPLACE Either these: echo "The flag of Canada (CA) is widely known." | $p r echo "She thinks GB-WLS's flag looks nicer than GB-ENG's." | $p r $p r <<< "Flags of CH and VA are 1:1, and NP's isn't rectangular." or these: $p r "The flag of Canada (CA) is widely known." $p r "She thinks GB-WLS's flag looks nicer than GB-ENG's." $p r "Flags of CH and VA are 1:1, and NP's isn't rectangular." should equally output: The flag of Canada (🇨🇦) is widely known. She thinks 🏴's flag looks nicer than 🏴's. Flags of 🇨🇭 and 🇻🇦 are 1:1, and 🇳🇵's isn't rectangular. TERRITORY Either these: echo CA | $p t echo CHVANP | $p t or these: $p t CA $p t CHVANP should equally output: 🇨🇦 🇨🇭🇻🇦🇳🇵 SUBDIVISION Either these: echo gbsct | $p s echo US-SC | $p s echo CA-QC | $p s or these: $p s gbsct $p s US-SC $p s CA-QC should equally output: 🏴 🏴 🏴 EOU exit "${1:-0}" ;} ############################################################################# main () { case "$1" in r) : f-string ;; t) : f-territ ;; s) : f-subdiv ;; h) usage 0 ;; *) usage 1 ;; esac "$_" "${2:-$(</dev/stdin)}" ;} ############################################################################# main "$@" exit 0
📆 2025-11-02