commit b73e742c5058ac6ce29183636edd201fc294db50
parent 09e654731efb4645277baa7c3653606c8cf2bd26
Author: Chris Hobbs <chris@rx14.co.uk>
Date: Fri, 9 Mar 2018 20:50:48 +0000
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
Diffstat:
M | clipmenu | | | 30 | ++++++++++++++++++++++-------- |
1 file changed, 22 insertions(+), 8 deletions(-)
diff --git a/clipmenu b/clipmenu
@@ -30,14 +30,28 @@ if [[ "$CM_LAUNCHER" == rofi ]]; then
set -- -dmenu "$@"
fi
-# 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() {
+ 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=$(
+ list_clips | "$CM_LAUNCHER" -l 8 "$@"
+ )
+fi
[[ $chosen_line ]] || exit 1