Remove the usage of ENV_* variables

This commit is contained in:
Konstantin Nazarov 2024-11-03 23:36:22 +00:00
parent 18c518af03
commit cc9cf1f360
Signed by: knazarov
GPG key ID: 4CFE0A42FA409C22
8 changed files with 35 additions and 69 deletions

View file

@ -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"

15
q
View file

@ -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 {}" \

View file

@ -1,27 +1,23 @@
#!/bin/sh
ENV_cat=cat
ENV_awk=awk
ENV_xdg_open=xdg-open
if [[ -z "$@" ]]; then
echo "^b .*$"
elif [[ "$1" == "--hint" ]]; then
shift
if [[ -f ~/.bookmarks.txt ]]; then
$ENV_cat ~/.bookmarks.txt | $ENV_awk '{print $1 " b " $2}'
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}'
cat ~/.bookmarks.txt | awk '{print $1 " b " $2}'
fi
elif [[ "$1" == "--preview" ]]; then
shift
echo "$1"
elif [[ "$1" == "--run" ]]; then
shift
$ENV_xdg_open "$1"
xdg-open "$1"
else
echo "Unexpected arguments: $@"
fi

View file

@ -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

10
q-calc
View file

@ -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

View file

@ -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

9
q-pass
View file

@ -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

10
q-run
View file

@ -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"