cdown / clipmenu

Clipboard management using dmenu
MIT License
1.11k stars 90 forks source link

Preserve exit code from launcher #150

Closed kankaristo closed 3 years ago

kankaristo commented 3 years ago

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 codes 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:

In order for this to work, the only change needed in clipmenu is to preserve the exit codes from the custom keybindings.

cdown commented 3 years ago

Looks good, thanks! Just a couple of nits.

kankaristo commented 3 years ago

@cdown, the requested changes as they are could lead to an error (exit "", which gives an error), so I've asked for more comments.

kankaristo commented 3 years ago

@cdown, I've implemented the suggested changes, and added a check so that the launcher exit code is used only if the variable is set.

cdown commented 3 years ago

Looks good, thanks.