From cc9cf1f36067bb5e5d1acbb5d9b8b2dbea6e7100 Mon Sep 17 00:00:00 2001 From: Konstantin Nazarov Date: Sun, 3 Nov 2024 23:36:22 +0000 Subject: [PATCH] Remove the usage of ENV_* variables --- flake.nix | 4 ---- q | 15 +++++---------- q-bookmarks | 32 ++++++++++++++------------------ q-browse | 9 +++------ q-calc | 10 +++------- q-clipboard | 15 +++++---------- q-pass | 9 ++------- q-run | 10 +++------- 8 files changed, 35 insertions(+), 69 deletions(-) diff --git a/flake.nix b/flake.nix index cecbebb..f04024a 100644 --- a/flake.nix +++ b/flake.nix @@ -48,11 +48,7 @@ ] ); - postFixup = '' - substituteInPlace $out/bin/q \ - --replace 'ENV_q="''${0##*/}"' "ENV_q=$out/bin/q" - # Ensure all dependencies are in PATH for fn in $out/bin/q*; do echo "wrapping $fn" diff --git a/q b/q index e4662ac..8119aa4 100755 --- a/q +++ b/q @@ -28,11 +28,6 @@ set -e -ENV_fzf=fzf -ENV_find=find -ENV_awk=awk -ENV_q=~/.config/q.sh - SELF=$(cd -P -- "$(dirname -- "$0")" && printf '%s\n' "$(pwd -P)/$(basename -- "$0")") if [[ -z "$Q_SCRIPT_DIR" ]]; then @@ -51,7 +46,7 @@ new_scripts_exist() { return 0 fi - NEWER_FILES="$($ENV_find "$Q_SCRIPT_DIR" -name "q-*" -newer "$INDEX_FILE")" + NEWER_FILES="$(find "$Q_SCRIPT_DIR" -name "q-*" -newer "$INDEX_FILE")" if [[ -z "$NEWER_FILES" ]]; then return 1 @@ -66,7 +61,7 @@ rebuild_index() { fi pushd "$Q_SCRIPT_DIR" >/dev/null - $ENV_find . -type f -name 'q-*' | while read -r FN + find . -type f -name 'q-*' | while read -r FN do FILENAME="$(echo "$FN" | sed 's/^\.\///g')" @@ -84,7 +79,7 @@ rebuild_hints() { fi pushd "$Q_SCRIPT_DIR" >/dev/null - $ENV_find . -type f -name 'q-*' | while read -r FN + find . -type f -name 'q-*' | while read -r FN do FILENAME="$(echo "$FN" | sed 's/^\.\///g')" @@ -98,7 +93,7 @@ get_scripts_for_cmd() { return fi - echo "$1" | $ENV_awk -f "$INDEX_FILE" | while read -r line + echo "$1" | awk -f "$INDEX_FILE" | while read -r line do echo "$line" done @@ -202,7 +197,7 @@ fi if [[ -z "$COMMAND" ]]; then PREF="$SELF -c" INITIAL="" - FZF_DEFAULT_COMMAND="$PREF '$INITIAL'" $ENV_fzf \ + FZF_DEFAULT_COMMAND="$PREF '$INITIAL'" fzf \ --bind "change:reload-sync:$PREF {q} || true" \ --ansi --query "$INITIAL" \ --preview "$SELF -p {}" \ diff --git a/q-bookmarks b/q-bookmarks index efdc3e9..48e6308 100755 --- a/q-bookmarks +++ b/q-bookmarks @@ -1,27 +1,23 @@ #!/bin/sh -ENV_cat=cat -ENV_awk=awk -ENV_xdg_open=xdg-open - if [[ -z "$@" ]]; then - echo "^b .*$" + echo "^b .*$" elif [[ "$1" == "--hint" ]]; then - shift - if [[ -f ~/.bookmarks.txt ]]; then - $ENV_cat ~/.bookmarks.txt | $ENV_awk '{print $1 " b " $2}' - fi + shift + if [[ -f ~/.bookmarks.txt ]]; then + cat ~/.bookmarks.txt | awk '{print $1 " b " $2}' + fi elif [[ "$1" == "--complete" ]]; then - shift - if [[ -f ~/.bookmarks.txt ]]; then - $ENV_cat ~/.bookmarks.txt | $ENV_awk '{print $1 " b " $2}' - fi + shift + if [[ -f ~/.bookmarks.txt ]]; then + cat ~/.bookmarks.txt | awk '{print $1 " b " $2}' + fi elif [[ "$1" == "--preview" ]]; then - shift - echo "$1" + shift + echo "$1" elif [[ "$1" == "--run" ]]; then - shift - $ENV_xdg_open "$1" + shift + xdg-open "$1" else - echo "Unexpected arguments: $@" + echo "Unexpected arguments: $@" fi diff --git a/q-browse b/q-browse index 579c9b1..dc4bfe7 100755 --- a/q-browse +++ b/q-browse @@ -1,8 +1,5 @@ #!/bin/sh -ENV_xdg_open=xdg-open -ENV_cut=cut - if [[ -z "$@" ]]; then echo "^f .*$" elif [[ "$1" == "--hint" ]]; then @@ -12,10 +9,10 @@ elif [[ "$1" == "--complete" ]]; then echo "0 $@" elif [[ "$1" == "--preview" ]]; then shift - URL="$(echo "$@" | $ENV_cut -d ' ' -f3-)" + URL="$(echo "$@" | cut -d ' ' -f3-)" echo "Will open '$URL' in firefox" elif [[ "$1" == "--run" ]]; then shift - URL="$(echo "$@" | $ENV_cut -d ' ' -f3-)" - setsid -f $ENV_xdg_open "$URL" + URL="$(echo "$@" | cut -d ' ' -f3-)" + setsid -f xdg-open "$URL" fi diff --git a/q-calc b/q-calc index 2d27c0c..5a05d4b 100755 --- a/q-calc +++ b/q-calc @@ -1,11 +1,7 @@ #!/bin/sh -ENV_bc=bc -ENV_wl_copy=wl-copy -ENV_cut=cut - calc() { - res="$(echo "$1" | $ENV_bc 2>/dev/null)" + res="$(echo "$1" | bc 2>/dev/null)" if [ "$res" == "" ]; then res="-" fi @@ -28,10 +24,10 @@ elif [[ "$1" == "--preview" ]]; then elif [[ "$1" == "--run" ]]; then shift echo "$1" - echo "$1" | (setsid -f $ENV_wl_copy) + echo "$1" | (setsid -f wl-copy) elif [[ "$1" == "--cli" ]]; then shift - calc "$(echo "$@" | $ENV_cut -d ' ' -f2-)" + calc "$(echo "$@" | cut -d ' ' -f2-)" else echo "Unexpected arguments: $@" fi diff --git a/q-clipboard b/q-clipboard index ee7ac4e..e2692c2 100755 --- a/q-clipboard +++ b/q-clipboard @@ -1,30 +1,25 @@ #!/bin/sh -ENV_cat=cat -ENV_tac=tac -ENV_base64=base64 -ENV_wl_copy=wl-copy - if [[ -z "$@" ]]; then echo "^c .*$" elif [[ "$1" == "--hint" ]]; then shift if [[ -f ~/.clipboard.txt ]]; then - $ENV_cat ~/.clipboard.txt | $ENV_tac + cat ~/.clipboard.txt | tac fi elif [[ "$1" == "--complete" ]]; then shift if [[ -f ~/.clipboard.txt ]]; then - $ENV_cat ~/.clipboard.txt | $ENV_tac + cat ~/.clipboard.txt | tac fi elif [[ "$1" == "--preview" ]]; then shift - echo "$1" | $ENV_base64 -d + echo "$1" | base64 -d elif [[ "$1" == "--run" ]]; then shift - TEXT="$(echo "$1" | $ENV_base64 -d)" + TEXT="$(echo "$1" | base64 -d)" echo "$TEXT" - echo -n "$TEXT" | (setsid -f $ENV_wl_copy) + echo -n "$TEXT" | (setsid -f wl-copy) else echo "Unexpected arguments: $@" fi diff --git a/q-pass b/q-pass index c17e107..9ad66e6 100755 --- a/q-pass +++ b/q-pass @@ -1,10 +1,5 @@ #!/bin/sh -ENV_pass=pass -ENV_find=find -ENV_sed=sed -ENV_wl_copy=wl-copy - if [[ -z "$@" ]]; then # Return a regular expression that should trigger # this subcommand. q.sh will then pass control to @@ -19,7 +14,7 @@ elif [[ "$1" == "--complete" ]]; then # passwords. This will be used to provide a list of # completions. cd ~/.password-store - $ENV_find . -name "*.gpg" | $ENV_sed -E 's/\.\/(.*)\.gpg/\1 p \1/' + find . -name "*.gpg" | sed -E 's/\.\/(.*)\.gpg/\1 p \1/' elif [[ "$1" == "--preview" ]]; then shift # This information will be displayed in the preview @@ -31,5 +26,5 @@ elif [[ "$1" == "--run" ]]; then # one of the options. We now decrypt the password # and place it to the clipboard. NAME="$1" - $ENV_pass "$NAME" | (setsid -f $ENV_wl_copy) + pass "$NAME" | (setsid -f wl-copy) fi diff --git a/q-run b/q-run index f1ef0a7..2d45df5 100755 --- a/q-run +++ b/q-run @@ -1,22 +1,18 @@ #!/bin/sh -ENV_awk=awk -ENV_sort=sort -ENV_uniq=uniq - find_all_executables() { { IFS=:; for d in $PATH; do for f in $d/*; do [ -f $f ] && [ -x $f ] && echo ${f##*/}; done; done; - } | $ENV_sort | $ENV_uniq + } | sort | uniq } if [[ -z "$@" ]]; then echo "^run [a-zA-Z0-9_-]*$" elif [[ "$1" == "--hint" ]]; then - find_all_executables | $ENV_awk '{print $1 " run " $1}' + find_all_executables | awk '{print $1 " run " $1}' elif [[ "$1" == "--complete" ]]; then shift - find_all_executables | $ENV_awk '{print $1 " run " $1}' + find_all_executables | awk '{print $1 " run " $1}' elif [[ "$1" == "--preview" ]]; then shift echo "Will run $1"