Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preserve exit code from launcher #150

Merged
merged 3 commits into from
Dec 19, 2020
Merged

Preserve exit code from launcher #150

merged 3 commits into from
Dec 19, 2020

Conversation

kankaristo
Copy link
Contributor

@kankaristo kankaristo commented Dec 17, 2020

This change is related to #57 (comment).

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:

  • 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.

This change is related to cdown#57 (comment).

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.
clipmenu Outdated Show resolved Hide resolved
clipmenu Outdated Show resolved Hide resolved
@cdown
Copy link
Owner

cdown commented Dec 18, 2020

Looks good, thanks! Just a couple of nits.

@kankaristo
Copy link
Contributor Author

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

Only set `$launcher_exit` if not running rofi-script, and only exit using `$launcher_exit` if it has been set. Otherwise, the last line (now with quoting around the variable) becomes `exit ""`, which causes an error.
@kankaristo
Copy link
Contributor Author

@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.

clipmenu Outdated Show resolved Hide resolved
@kankaristo kankaristo requested a review from cdown December 19, 2020 16:23
@cdown
Copy link
Owner

cdown commented Dec 19, 2020

Looks good, thanks.

@cdown cdown merged commit 25219b7 into cdown:develop Dec 19, 2020
@kankaristo kankaristo deleted the patch-1 branch December 19, 2020 16:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants