diff options
| author | Suleyman Farajli <suleyman@farajli.net> | 2025-11-04 23:11:36 +0400 |
|---|---|---|
| committer | Suleyman Farajli <suleyman@farajli.net> | 2025-11-04 23:11:36 +0400 |
| commit | 1cc83ac39fe8ac5527af41b9ede23f0cd1b3b073 (patch) | |
| tree | fa1bb8110df813ae494fba8c349362fbff2299c7 /scripts/gui/sclip | |
| parent | f5aa31946cf56007b48696b029c5f0929a91612a (diff) | |
feat(sclip): add silent mode and improve clipboard handling
Diffstat (limited to 'scripts/gui/sclip')
| -rwxr-xr-x | scripts/gui/sclip | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/scripts/gui/sclip b/scripts/gui/sclip index 3666448..3d2caa5 100755 --- a/scripts/gui/sclip +++ b/scripts/gui/sclip @@ -18,12 +18,15 @@ exit 0 check_program "xclip" i_flg=0 -while getopts "f:c:ih" option; do +silent=0 +while getopts "f:c:sih" option; do case "${option}" in f) filepath="${OPTARG}" ;; c) input="${OPTARG}" ;; + s) silent=1 ;; + i) i_flg=1 ;; h) help ;; @@ -38,6 +41,11 @@ shift $((OPTIND - 1)) if [ -n "${filepath}" ]; then mime_type=$(file --mime-type -b "${filepath}") + + if [ "${silent}" -eq 1 ]; then + run "xclip -selection clipboard -t ${mime_type} -i ${filepath}" + fi + run --success-notify "${filepath} copied" \ --failure-notify "${filepath} failed to copy" \ "xclip -selection clipboard -t ${mime_type} -i ${filepath}" @@ -46,8 +54,17 @@ fi [ "${i_flg}" -eq 1 ] && input=$(cat) if [ -n "${input}" ]; then + # Don't use `run` since pipes are used printf '%s' "${input}" | xclip -selection clipboard - exit 0 + + if [ $? -eq 0 ]; then + [ "${silent}" -eq 0 ] && send_notification "${argv0}:" "'${input}' copied" + exit 0 + fi + + [ "${silent}" -eq 0 ] && send_notification "${argv0}:" "'${input}' failed to copy" + + exit 1 fi run "xclip -o -selection clipboard" |
