From 1cc83ac39fe8ac5527af41b9ede23f0cd1b3b073 Mon Sep 17 00:00:00 2001 From: Suleyman Farajli Date: Tue, 4 Nov 2025 23:11:36 +0400 Subject: feat(sclip): add silent mode and improve clipboard handling --- scripts/gui/sclip | 21 +++++++++++++++++++-- 1 file 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" -- cgit v1.2.3