Remove the usage of ENV_* variables
This commit is contained in:
parent
18c518af03
commit
cc9cf1f360
8 changed files with 35 additions and 69 deletions
|
@ -48,11 +48,7 @@
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
postFixup = ''
|
postFixup = ''
|
||||||
substituteInPlace $out/bin/q \
|
|
||||||
--replace 'ENV_q="''${0##*/}"' "ENV_q=$out/bin/q"
|
|
||||||
|
|
||||||
# Ensure all dependencies are in PATH
|
# Ensure all dependencies are in PATH
|
||||||
for fn in $out/bin/q*; do
|
for fn in $out/bin/q*; do
|
||||||
echo "wrapping $fn"
|
echo "wrapping $fn"
|
||||||
|
|
15
q
15
q
|
@ -28,11 +28,6 @@
|
||||||
|
|
||||||
set -e
|
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")")
|
SELF=$(cd -P -- "$(dirname -- "$0")" && printf '%s\n' "$(pwd -P)/$(basename -- "$0")")
|
||||||
|
|
||||||
if [[ -z "$Q_SCRIPT_DIR" ]]; then
|
if [[ -z "$Q_SCRIPT_DIR" ]]; then
|
||||||
|
@ -51,7 +46,7 @@ new_scripts_exist() {
|
||||||
return 0
|
return 0
|
||||||
fi
|
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
|
if [[ -z "$NEWER_FILES" ]]; then
|
||||||
return 1
|
return 1
|
||||||
|
@ -66,7 +61,7 @@ rebuild_index() {
|
||||||
fi
|
fi
|
||||||
|
|
||||||
pushd "$Q_SCRIPT_DIR" >/dev/null
|
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
|
do
|
||||||
FILENAME="$(echo "$FN" | sed 's/^\.\///g')"
|
FILENAME="$(echo "$FN" | sed 's/^\.\///g')"
|
||||||
|
|
||||||
|
@ -84,7 +79,7 @@ rebuild_hints() {
|
||||||
fi
|
fi
|
||||||
|
|
||||||
pushd "$Q_SCRIPT_DIR" >/dev/null
|
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
|
do
|
||||||
FILENAME="$(echo "$FN" | sed 's/^\.\///g')"
|
FILENAME="$(echo "$FN" | sed 's/^\.\///g')"
|
||||||
|
|
||||||
|
@ -98,7 +93,7 @@ get_scripts_for_cmd() {
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "$1" | $ENV_awk -f "$INDEX_FILE" | while read -r line
|
echo "$1" | awk -f "$INDEX_FILE" | while read -r line
|
||||||
do
|
do
|
||||||
echo "$line"
|
echo "$line"
|
||||||
done
|
done
|
||||||
|
@ -202,7 +197,7 @@ fi
|
||||||
if [[ -z "$COMMAND" ]]; then
|
if [[ -z "$COMMAND" ]]; then
|
||||||
PREF="$SELF -c"
|
PREF="$SELF -c"
|
||||||
INITIAL=""
|
INITIAL=""
|
||||||
FZF_DEFAULT_COMMAND="$PREF '$INITIAL'" $ENV_fzf \
|
FZF_DEFAULT_COMMAND="$PREF '$INITIAL'" fzf \
|
||||||
--bind "change:reload-sync:$PREF {q} || true" \
|
--bind "change:reload-sync:$PREF {q} || true" \
|
||||||
--ansi --query "$INITIAL" \
|
--ansi --query "$INITIAL" \
|
||||||
--preview "$SELF -p {}" \
|
--preview "$SELF -p {}" \
|
||||||
|
|
32
q-bookmarks
32
q-bookmarks
|
@ -1,27 +1,23 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
ENV_cat=cat
|
|
||||||
ENV_awk=awk
|
|
||||||
ENV_xdg_open=xdg-open
|
|
||||||
|
|
||||||
if [[ -z "$@" ]]; then
|
if [[ -z "$@" ]]; then
|
||||||
echo "^b .*$"
|
echo "^b .*$"
|
||||||
elif [[ "$1" == "--hint" ]]; then
|
elif [[ "$1" == "--hint" ]]; then
|
||||||
shift
|
shift
|
||||||
if [[ -f ~/.bookmarks.txt ]]; then
|
if [[ -f ~/.bookmarks.txt ]]; then
|
||||||
$ENV_cat ~/.bookmarks.txt | $ENV_awk '{print $1 " b " $2}'
|
cat ~/.bookmarks.txt | awk '{print $1 " b " $2}'
|
||||||
fi
|
fi
|
||||||
elif [[ "$1" == "--complete" ]]; then
|
elif [[ "$1" == "--complete" ]]; then
|
||||||
shift
|
shift
|
||||||
if [[ -f ~/.bookmarks.txt ]]; then
|
if [[ -f ~/.bookmarks.txt ]]; then
|
||||||
$ENV_cat ~/.bookmarks.txt | $ENV_awk '{print $1 " b " $2}'
|
cat ~/.bookmarks.txt | awk '{print $1 " b " $2}'
|
||||||
fi
|
fi
|
||||||
elif [[ "$1" == "--preview" ]]; then
|
elif [[ "$1" == "--preview" ]]; then
|
||||||
shift
|
shift
|
||||||
echo "$1"
|
echo "$1"
|
||||||
elif [[ "$1" == "--run" ]]; then
|
elif [[ "$1" == "--run" ]]; then
|
||||||
shift
|
shift
|
||||||
$ENV_xdg_open "$1"
|
xdg-open "$1"
|
||||||
else
|
else
|
||||||
echo "Unexpected arguments: $@"
|
echo "Unexpected arguments: $@"
|
||||||
fi
|
fi
|
||||||
|
|
9
q-browse
9
q-browse
|
@ -1,8 +1,5 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
ENV_xdg_open=xdg-open
|
|
||||||
ENV_cut=cut
|
|
||||||
|
|
||||||
if [[ -z "$@" ]]; then
|
if [[ -z "$@" ]]; then
|
||||||
echo "^f .*$"
|
echo "^f .*$"
|
||||||
elif [[ "$1" == "--hint" ]]; then
|
elif [[ "$1" == "--hint" ]]; then
|
||||||
|
@ -12,10 +9,10 @@ elif [[ "$1" == "--complete" ]]; then
|
||||||
echo "0 $@"
|
echo "0 $@"
|
||||||
elif [[ "$1" == "--preview" ]]; then
|
elif [[ "$1" == "--preview" ]]; then
|
||||||
shift
|
shift
|
||||||
URL="$(echo "$@" | $ENV_cut -d ' ' -f3-)"
|
URL="$(echo "$@" | cut -d ' ' -f3-)"
|
||||||
echo "Will open '$URL' in firefox"
|
echo "Will open '$URL' in firefox"
|
||||||
elif [[ "$1" == "--run" ]]; then
|
elif [[ "$1" == "--run" ]]; then
|
||||||
shift
|
shift
|
||||||
URL="$(echo "$@" | $ENV_cut -d ' ' -f3-)"
|
URL="$(echo "$@" | cut -d ' ' -f3-)"
|
||||||
setsid -f $ENV_xdg_open "$URL"
|
setsid -f xdg-open "$URL"
|
||||||
fi
|
fi
|
||||||
|
|
10
q-calc
10
q-calc
|
@ -1,11 +1,7 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
ENV_bc=bc
|
|
||||||
ENV_wl_copy=wl-copy
|
|
||||||
ENV_cut=cut
|
|
||||||
|
|
||||||
calc() {
|
calc() {
|
||||||
res="$(echo "$1" | $ENV_bc 2>/dev/null)"
|
res="$(echo "$1" | bc 2>/dev/null)"
|
||||||
if [ "$res" == "" ]; then
|
if [ "$res" == "" ]; then
|
||||||
res="-"
|
res="-"
|
||||||
fi
|
fi
|
||||||
|
@ -28,10 +24,10 @@ elif [[ "$1" == "--preview" ]]; then
|
||||||
elif [[ "$1" == "--run" ]]; then
|
elif [[ "$1" == "--run" ]]; then
|
||||||
shift
|
shift
|
||||||
echo "$1"
|
echo "$1"
|
||||||
echo "$1" | (setsid -f $ENV_wl_copy)
|
echo "$1" | (setsid -f wl-copy)
|
||||||
elif [[ "$1" == "--cli" ]]; then
|
elif [[ "$1" == "--cli" ]]; then
|
||||||
shift
|
shift
|
||||||
calc "$(echo "$@" | $ENV_cut -d ' ' -f2-)"
|
calc "$(echo "$@" | cut -d ' ' -f2-)"
|
||||||
else
|
else
|
||||||
echo "Unexpected arguments: $@"
|
echo "Unexpected arguments: $@"
|
||||||
fi
|
fi
|
||||||
|
|
15
q-clipboard
15
q-clipboard
|
@ -1,30 +1,25 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
ENV_cat=cat
|
|
||||||
ENV_tac=tac
|
|
||||||
ENV_base64=base64
|
|
||||||
ENV_wl_copy=wl-copy
|
|
||||||
|
|
||||||
if [[ -z "$@" ]]; then
|
if [[ -z "$@" ]]; then
|
||||||
echo "^c .*$"
|
echo "^c .*$"
|
||||||
elif [[ "$1" == "--hint" ]]; then
|
elif [[ "$1" == "--hint" ]]; then
|
||||||
shift
|
shift
|
||||||
if [[ -f ~/.clipboard.txt ]]; then
|
if [[ -f ~/.clipboard.txt ]]; then
|
||||||
$ENV_cat ~/.clipboard.txt | $ENV_tac
|
cat ~/.clipboard.txt | tac
|
||||||
fi
|
fi
|
||||||
elif [[ "$1" == "--complete" ]]; then
|
elif [[ "$1" == "--complete" ]]; then
|
||||||
shift
|
shift
|
||||||
if [[ -f ~/.clipboard.txt ]]; then
|
if [[ -f ~/.clipboard.txt ]]; then
|
||||||
$ENV_cat ~/.clipboard.txt | $ENV_tac
|
cat ~/.clipboard.txt | tac
|
||||||
fi
|
fi
|
||||||
elif [[ "$1" == "--preview" ]]; then
|
elif [[ "$1" == "--preview" ]]; then
|
||||||
shift
|
shift
|
||||||
echo "$1" | $ENV_base64 -d
|
echo "$1" | base64 -d
|
||||||
elif [[ "$1" == "--run" ]]; then
|
elif [[ "$1" == "--run" ]]; then
|
||||||
shift
|
shift
|
||||||
TEXT="$(echo "$1" | $ENV_base64 -d)"
|
TEXT="$(echo "$1" | base64 -d)"
|
||||||
echo "$TEXT"
|
echo "$TEXT"
|
||||||
echo -n "$TEXT" | (setsid -f $ENV_wl_copy)
|
echo -n "$TEXT" | (setsid -f wl-copy)
|
||||||
else
|
else
|
||||||
echo "Unexpected arguments: $@"
|
echo "Unexpected arguments: $@"
|
||||||
fi
|
fi
|
||||||
|
|
9
q-pass
9
q-pass
|
@ -1,10 +1,5 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
ENV_pass=pass
|
|
||||||
ENV_find=find
|
|
||||||
ENV_sed=sed
|
|
||||||
ENV_wl_copy=wl-copy
|
|
||||||
|
|
||||||
if [[ -z "$@" ]]; then
|
if [[ -z "$@" ]]; then
|
||||||
# Return a regular expression that should trigger
|
# Return a regular expression that should trigger
|
||||||
# this subcommand. q.sh will then pass control to
|
# 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
|
# passwords. This will be used to provide a list of
|
||||||
# completions.
|
# completions.
|
||||||
cd ~/.password-store
|
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
|
elif [[ "$1" == "--preview" ]]; then
|
||||||
shift
|
shift
|
||||||
# This information will be displayed in the preview
|
# 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
|
# one of the options. We now decrypt the password
|
||||||
# and place it to the clipboard.
|
# and place it to the clipboard.
|
||||||
NAME="$1"
|
NAME="$1"
|
||||||
$ENV_pass "$NAME" | (setsid -f $ENV_wl_copy)
|
pass "$NAME" | (setsid -f wl-copy)
|
||||||
fi
|
fi
|
||||||
|
|
10
q-run
10
q-run
|
@ -1,22 +1,18 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
ENV_awk=awk
|
|
||||||
ENV_sort=sort
|
|
||||||
ENV_uniq=uniq
|
|
||||||
|
|
||||||
find_all_executables() {
|
find_all_executables() {
|
||||||
{
|
{
|
||||||
IFS=:; for d in $PATH; do for f in $d/*; do [ -f $f ] && [ -x $f ] && echo ${f##*/}; done; done;
|
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
|
if [[ -z "$@" ]]; then
|
||||||
echo "^run [a-zA-Z0-9_-]*$"
|
echo "^run [a-zA-Z0-9_-]*$"
|
||||||
elif [[ "$1" == "--hint" ]]; then
|
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
|
elif [[ "$1" == "--complete" ]]; then
|
||||||
shift
|
shift
|
||||||
find_all_executables | $ENV_awk '{print $1 " run " $1}'
|
find_all_executables | awk '{print $1 " run " $1}'
|
||||||
elif [[ "$1" == "--preview" ]]; then
|
elif [[ "$1" == "--preview" ]]; then
|
||||||
shift
|
shift
|
||||||
echo "Will run $1"
|
echo "Will run $1"
|
||||||
|
|
Loading…
Reference in a new issue