clipmenu

Simple clipboard management using dmenu
git clone https://git.sinitax.com/cdown/clipmenu
Log | Files | Refs | README | LICENSE | sfeed.txt

commit 8c864ac5df941c1e91bbf65118ffd5d51a51a701
parent a882cf9732adc24e99e0fbe860ead02e72e24b92
Author: Sami Kankaristo <sami@kankaristo.fi>
Date:   Thu, 17 Dec 2020 23:03:47 +0200

Preserve exit code from launcher

This change is related to https://github.com/cdown/clipmenu/issues/57#issuecomment-740123283.

If `clipmenu` "preserves" the exit code from the launcher (exits with the same code as the launcher), the exit code's from Rofi's custom keybindings can be used with `clipmenu`.

For example, I'm using the following script bound to `Super+v`:
```
#!/bin/bash

trap "exit" INT

# Run clipmenu
CM_LAUNCHER=rofi clipmenu -p "Paste" -mesg "Use Shift+Delete to delete an item" \
    -kb-delete-entry "" -kb-custom-1 "Shift+Delete" \
    -kb-accept-alt "" -kb-custom-2 "Shift+Return"

exit_code=$?

case $exit_code in
    0) xdotool key "shift+Insert" ;;
    10) clipdel -d ^"$(xsel -b)"$; "$0" ;;
    *) exit $exit_code ;;
esac
```

With the above script, I have 3 different options when running `clipmenu`:
- if I press `Return`, the selected item is pasted to where my cursor currently is (a bit hackily with `xdotool`)
- if I press `Shift+Return`, the selected item is sent to the clipboard ("default" `clipmenu` behavior)
- if I press `Shift+Delete`, the selected item is deleted from `clipmenu`, and the script runs itself again (essentially keeps `clipmenu` open)

In order for this to work, the only change needed in `clipmenu` is to preserve the exit codes from the custom keybindings.
Diffstat:
Mclipmenu | 4++++
1 file changed, 4 insertions(+), 0 deletions(-)

diff --git a/clipmenu b/clipmenu @@ -58,6 +58,8 @@ else chosen_line=$(list_clips | "$CM_LAUNCHER" "${launcher_args[@]}" "$@") fi +launcher_exit=$? + [[ $chosen_line ]] || exit 1 file=$cache_dir/$(cksum <<< "$chosen_line") [[ -f "$file" ]] || exit 2 @@ -69,3 +71,5 @@ done if (( CM_OUTPUT_CLIP )); then cat "$file" fi + +exit $launcher_exit