From d03068dba7a1c5708c2779921d7a945eb55377b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yann=20B=C3=BCchau?= Date: Tue, 27 Sep 2022 21:01:44 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Add=20-n=20option=20to=20prevent=20?= =?UTF-8?q?newline=20after=20emoji=20(#12)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adds another commandline option `-n` to the application which prevents newlines from being added at the end of each output. Disabled by default. Co-authored-by: Marty Oehme --- CHANGELOG.md | 4 +++- README.md | 19 ++++++++++++++++++- bemoji | 9 +++++++-- test/bemoji_cmds.bats | 12 ++++++++++++ 4 files changed, 40 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8f92f22..fe720ef 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] - +### Added + +- Add new option `-n` which suppresses printing the final newline character in output ### Changed diff --git a/README.md b/README.md index 5960385..185fb0a 100644 --- a/README.md +++ b/README.md @@ -170,7 +170,7 @@ To display *only* the emoji list passed in, pass an extra `-P` flag to bemoji. The path can also be a weblink which bemoji will download and use: -``` +```bash bemoji -f "https://raw.githubusercontent.com/jchook/emoji-menu/master/data/emojis.txt" ``` @@ -190,6 +190,22 @@ Other valid options for this setting are `emoji`, `math`, `none`. If set to `none` and no files are in the emoji directory, bemoji will simply complain and not show anything. +### Do not skip to new line after output + +By default, bemoji will craft the final output using a typical `echo` call for anything it prints directly. + +That means, it will also contain a final newline character. +So, for example it would technically output `🦊\n` for the `fox` emoji, +which skips to a new line in most circumstances. + +If you wish to prevent this character in the final output, use: + +```bash +bemoji -n +``` + +Using this option will suppress the newline character and *only* print `🦊` as its output. + ### Using a custom tool for picking, clipping, typing If you want to replace one of the default supported tools with your own you can do this through environment variables: @@ -234,6 +250,7 @@ BEMOJI_CLIP_CMD=wl-copy # which clipboard tool to use BEMOJI_TYPE_CMD=wtype # which typing tool to use (ydotool will NOT work) BEMOJI_PRIVATE_MODE=false # whether to save new entries BEMOJI_IGNORE_RECENT=false # whether to display recent entries +BEMOJI_ECHO_NEWLINE=true # whether to end the output with a newline character ``` ## 🤗 Issues diff --git a/bemoji b/bemoji index 2af9073..41dc8bc 100755 --- a/bemoji +++ b/bemoji @@ -13,6 +13,8 @@ bm_history_file="${bm_cache_dir}/bemoji-history.txt" # Command to run after user chooses an emoji bm_default_cmd="$BEMOJI_DEFAULT_CMD" +# Newline after echo +bm_echo_newline=${BEMOJI_ECHO_NEWLINE:-true} # Do not save choices bm_private_mode=${BEMOJI_PRIVATE_MODE:-false} # Do not sort results @@ -31,6 +33,7 @@ usage() { echo " -e Only echo out the picked emoji." echo "" echo " Other options:" + echo " -n Do not print a newline after the picked emoji." echo " -p Do not save picked emoji to recent history." echo " -P Do not order emoji by recently used." echo " -D Choose specific default lists to download if none found locally." @@ -48,12 +51,13 @@ version() { } # Get Options -while getopts ":f:D:tcepPhv" o; do +while getopts ":f:D:tcenpPhv" o; do case "${o}" in f) BEMOJI_CUSTOM_LIST="${OPTARG}" ;; t) bm_cmds+=(_typer) ;; c) bm_cmds+=(_clipper) ;; e) bm_cmds+=(cat) ;; + n) bm_echo_newline=false;; D) BEMOJI_DOWNLOAD_LIST="${OPTARG}" ;; p) bm_private_mode=true ;; P) bm_ignore_recent=true ;; @@ -209,7 +213,8 @@ case "$exit_value" in bm_cmds+=(_clipper) fi for cmd in "${bm_cmds[@]}"; do - echo "$result" | "$cmd" + [ "$bm_echo_newline" = true ] && echo_opts= || echo_opts=-n + echo $echo_opts "$result" | "$cmd" done ;; 10) diff --git a/test/bemoji_cmds.bats b/test/bemoji_cmds.bats index 3f7f681..2b0a937 100644 --- a/test/bemoji_cmds.bats +++ b/test/bemoji_cmds.bats @@ -63,3 +63,15 @@ typing result" BEMOJI_DEFAULT_CMD="echo my custom command" BEMOJI_CLIP_CMD="echo my clipping" run bemoji -c 3>&- assert_output "my clipping" } + +@test "Prints output with newline by default" { + bats_require_minimum_version 1.5.0 + BEMOJI_PICKER_CMD="echo heart" run --keep-empty-lines -- bemoji -e + assert_output --regexp '^heart\n$' +} + +@test "Prints output without newline on -n option" { + bats_require_minimum_version 1.5.0 + BEMOJI_PICKER_CMD="echo heart" run --keep-empty-lines -- bemoji -ne + assert_output --regexp '^heart$' +}