Allow use as a rofi script (#68)

* Allow use as a rofi script

* fixup! Allow use as a rofi script

* fixup! Allow use as a rofi script

* fixup! Allow use as a rofi script
This commit is contained in:
Chris Hobbs 2018-03-09 20:50:48 +00:00 committed by Chris Down
parent 09e654731e
commit b73e742c50

View file

@ -30,14 +30,28 @@ if [[ "$CM_LAUNCHER" == rofi ]]; then
set -- -dmenu "$@"
fi
list_clips() {
cat "$cache_file_prefix"_* /dev/null | LC_ALL=C sort -rnk 1 | cut -d' ' -f2- | awk '!seen[$0]++'
}
if [[ "$CM_LAUNCHER" == rofi-script ]]; then
if ! (( $# )); then
list_clips
exit
else
# https://github.com/koalaman/shellcheck/issues/1141
# shellcheck disable=SC2124
chosen_line="${@: -1}"
fi
else
# It's okay to hardcode `-l 8` here as a sensible default without checking
# whether `-l` is also in "$@", because the way that dmenu works allows a later
# argument to override an earlier one. That is, if the user passes in `-l`, our
# one will be ignored.
chosen_line=$(
cat "$cache_file_prefix"_* /dev/null | LC_ALL=C sort -rnk 1 |
cut -d' ' -f2- | awk '!seen[$0]++' | "$CM_LAUNCHER" -l 8 "$@"
list_clips | "$CM_LAUNCHER" -l 8 "$@"
)
fi
[[ $chosen_line ]] || exit 1