diff --git a/CHANGELOG.md b/CHANGELOG.md index c13bcce..3b1018c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,9 +10,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - Pass through return code 1 from selection tool -- (!) Number of displayed recent emoji can be set with `-P` option. This replaces previous `-P` - history flag toggle. Use number to set amount of recent entries to display, `-P3`. To - completely hide history use `-P0` +- (!) Number of displayed recent emoji can be set with `-P` option: + This replaces previous `-P` history flag toggle. Use number to set amount of recent + entries to display, `-P3`. To completely hide history use `-P0`. +- Add nerdfont emoji set download with `-D nerd` ### Changed diff --git a/README.md b/README.md index 6211079..13e989f 100644 --- a/README.md +++ b/README.md @@ -184,24 +184,24 @@ The path can also be a weblink which bemoji will download and use: bemoji -f "https://raw.githubusercontent.com/jchook/emoji-menu/master/data/emojis.txt" ``` -### Download additional emoji set +### Download additional emoji sets bemoji automatically downloads an emoji list for you to use on first invocation. -By default, it only downloads emoji, though you can have it download math symbols as well. +By default, it only downloads emoji, though you can have it download math symbols and nerdfont icons as well. To download additional sets, execute bemoji like the following: ```bash bemoji -D all ``` -This will download *all* default sets bemoji knows - which is currently the default emoji list and a long list of math symbols. -Other valid options for this setting are `emoji`, `math`, `none`. +This will download *all* default sets bemoji knows - which is currently the default emoji list, nerd font icons, and a long list of math symbols. +Other valid options for this setting are `emoji`, `math`, `nerd`, `none`. ```bash -bemoji -D "math emoji" +bemoji -D "math emoji nerd" ``` -The above command is equivalent as you can mention multiple sets you want downloaded. +The above command is equivalent to `all` as you can mention multiple sets you want downloaded. If set to `none` and no files are in the emoji directory, bemoji will complain and not show anything. diff --git a/bemoji b/bemoji index f054141..1bb2cc2 100755 --- a/bemoji +++ b/bemoji @@ -37,7 +37,7 @@ usage() { echo " -p Do not save picked emoji to recent history." echo " -P Limit number of recent emoji to display." echo " -D Choose from default lists to download." - echo " Valid choices: all|none|emoji|math (multiple choices possible)." + echo " Valid choices: all|none|emoji|math|nerd (multiple choices possible)." echo " -f Use a custom emoji database. Can be a url which will be retrieved." echo " -v Display current program version and directory configuration." echo " -h Show this help." @@ -81,6 +81,7 @@ prepare_db() { elif echo "$BEMOJI_DOWNLOAD_LIST" | grep -q -e 'all'; then dl_default_emoji dl_math_symbols + dl_nerd_symbols return else if echo "$BEMOJI_DOWNLOAD_LIST" | grep -q -e 'emoji'; then @@ -89,6 +90,9 @@ prepare_db() { if echo "$BEMOJI_DOWNLOAD_LIST" | grep -q -e 'math'; then dl_math_symbols fi + if echo "$BEMOJI_DOWNLOAD_LIST" | grep -q -e 'nerd'; then + dl_nerd_symbols + fi fi fi if [ -n "$(find "$bm_db_location" -maxdepth 0 -type d -empty 2>/dev/null)" ]; then @@ -107,6 +111,13 @@ dl_math_symbols() { grep -ve '^#' | cut -d';' -f3,7 | sed -e 's/;/ /' >"$bm_db_location/math.txt" printf "Downloaded math symbols set.\n" } +dl_nerd_symbols() { + local nerd all + nerd=$(curl -sSL "https://raw.githubusercontent.com/ryanoasis/nerd-fonts/master/css/nerd-fonts-generated.css") + all+=$(printf "%s" "$nerd" | sed -ne '/\.nf-/p' -e '/\s*[^_]content:/p' | sed -e 'N;s/^\.nf-\(.*\):before.* content: \"\\\(.*\)\";/\\U\2 \1/') + echo -e "$all" > "$bm_db_location/nerdfont.txt" + printf "Downloaded nerdfont symbols set.\n" +} gather_emojis() { if [ -n "$BEMOJI_CUSTOM_LIST" ] && [ -f "$BEMOJI_CUSTOM_LIST" ]; then diff --git a/test/bemoji_download.bats b/test/bemoji_download.bats index 6fda12b..707aaf7 100644 --- a/test/bemoji_download.bats +++ b/test/bemoji_download.bats @@ -38,3 +38,11 @@ emoji2 picked up" assert_equal "$outcome" "Σ GREEK CAPITAL LETTER SIGMA" unstub curl } +@test "Runs nerdfont download on -D nerd option" { + stub curl \ + "printf 'meangingless\nafiller lines\n.nf-md-pipe_wrench:before { \n content: \"\\\f1354\";\n }'" + run bemoji -D nerd 3>&- + outcome=$(cat "$BEMOJI_DB_LOCATION/nerdfont.txt") + assert_equal "$outcome" "󱍔 md-pipe_wrench" + unstub curl +}