add more command line options, general cleanup
This commit is contained in:
parent
82c934123d
commit
2d22802ee2
|
@ -6,12 +6,15 @@
|
||||||
- An implementation of POSIX Utilities (`coreutils`, `bsdutils`, `busybox`, ...)
|
- An implementation of POSIX Utilities (`coreutils`, `bsdutils`, `busybox`, ...)
|
||||||
- An implementation of `file(1)` that supports `-b` and `-i` for mime-types (yours should)
|
- An implementation of `file(1)` that supports `-b` and `-i` for mime-types (yours should)
|
||||||
- `ed` (mentioning this separately since many unixes/distributions have it separately)
|
- `ed` (mentioning this separately since many unixes/distributions have it separately)
|
||||||
|
- [`clipnotify`](https://github.com/cdown/clipnotify)
|
||||||
- A newline-delimited menu program (`dmenu`, `rofi`, `bemenu`, `fzfmenu`, ...)
|
- A newline-delimited menu program (`dmenu`, `rofi`, `bemenu`, `fzfmenu`, ...)
|
||||||
- (Optional, but recommended) `notify-send`
|
- (Optional, but recommended) `notify-send`
|
||||||
|
|
||||||
## using
|
## using
|
||||||
put `shclip-{daemon,menu}` in your `$PATH` and start `shclip-daemon` in a way where it can read `$DISPLAY`. everything should Just Work, hopefully. to use the menu, run `shclip-menu`
|
put `shclip-{daemon,menu}` in your `$PATH` and start `shclip-daemon` in a way where it can read `$DISPLAY`. everything should Just Work, hopefully. to use the menu, run `shclip-menu`
|
||||||
|
|
||||||
|
to see the command-line opticons for `shclip-daemon`, run `shclip-daemon -h`
|
||||||
|
|
||||||
`shclip` reads a config file at `$XDG_CONFIG_HOME/shclip/config` and reads filters from `$XDG_CONFIG_HOME/shclip/filter.sh`. if `config` doesn't exist, then the defaults as specified in the file are used. if `filter.sh` doesn't exist, then filtering won't happen whether it's enabled or not.
|
`shclip` reads a config file at `$XDG_CONFIG_HOME/shclip/config` and reads filters from `$XDG_CONFIG_HOME/shclip/filter.sh`. if `config` doesn't exist, then the defaults as specified in the file are used. if `filter.sh` doesn't exist, then filtering won't happen whether it's enabled or not.
|
||||||
|
|
||||||
if filtering is enabled, every text clip will be sent to the stdin of `filter.sh` and be replaced by its stdout. A simple replacement filter is provided as an example
|
if filtering is enabled, every text clip will be sent to the stdin of `filter.sh` and be replaced by its stdout. A simple replacement filter is provided as an example
|
||||||
|
|
|
@ -22,10 +22,13 @@ SHCLIP_TEMP_DIR="${XDG_RUNTIME_DIR:-${TMPDIR:-/tmp}}/shclip-$USER-$DISPLAY"
|
||||||
|
|
||||||
errecho() { printf '%s\n' "$*" >&2; }
|
errecho() { printf '%s\n' "$*" >&2; }
|
||||||
exists() { command -v "$@" >/dev/null 2>&1; }
|
exists() { command -v "$@" >/dev/null 2>&1; }
|
||||||
|
notify() {
|
||||||
|
errecho "$*"
|
||||||
|
exists notify-send && notify-send "$*"
|
||||||
|
:
|
||||||
|
}
|
||||||
fail() {
|
fail() {
|
||||||
errecho "error: $BN: $*"
|
notify "error: $BN: $*"
|
||||||
exists notify-send && notify-send "error: $BN: $*"
|
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,12 +44,10 @@ cleanup() {
|
||||||
toggle() {
|
toggle() {
|
||||||
if [ -z "$SHCLIP_ENABLED" ]; then
|
if [ -z "$SHCLIP_ENABLED" ]; then
|
||||||
SHCLIP_ENABLED=1
|
SHCLIP_ENABLED=1
|
||||||
errecho "shclip enabled!"
|
notify "shclip enabled!"
|
||||||
exists notify-send && notify-send "shclip enabled!"
|
|
||||||
else
|
else
|
||||||
SHCLIP_ENABLED=""
|
SHCLIP_ENABLED=""
|
||||||
errecho "shclip disabled!"
|
notify "shclip disabled!"
|
||||||
exists notify-send && notify-send "shclip disabled!"
|
|
||||||
fi
|
fi
|
||||||
kill "$clipnotify_pid"
|
kill "$clipnotify_pid"
|
||||||
}
|
}
|
||||||
|
@ -54,12 +55,10 @@ toggle() {
|
||||||
filter_toggle() {
|
filter_toggle() {
|
||||||
if [ -z "$SHCLIP_FILTER_ENABLED" ]; then
|
if [ -z "$SHCLIP_FILTER_ENABLED" ]; then
|
||||||
SHCLIP_FILTER_ENABLED=1
|
SHCLIP_FILTER_ENABLED=1
|
||||||
errecho "shclip filter enabled!"
|
notify "shclip filter enabled!"
|
||||||
exists notify-send && notify-send "shclip filter enabled!"
|
|
||||||
else
|
else
|
||||||
SHCLIP_FILTER_ENABLED=""
|
SHCLIP_FILTER_ENABLED=""
|
||||||
errecho "shclip filter disabled!"
|
notify "shclip filter disabled!"
|
||||||
exists notify-send && notify-send "shclip filter disabled!"
|
|
||||||
fi
|
fi
|
||||||
kill "$clipnotify_pid"
|
kill "$clipnotify_pid"
|
||||||
}
|
}
|
||||||
|
@ -124,8 +123,7 @@ updateclip() {
|
||||||
# check if clip exceeds memory limit
|
# check if clip exceeds memory limit
|
||||||
sz="$(du -k "$BUFFER")"
|
sz="$(du -k "$BUFFER")"
|
||||||
if [ "${sz%%${TAB}*}" -gt "$SHCLIP_MEMORY_LIMIT" ]; then
|
if [ "${sz%%${TAB}*}" -gt "$SHCLIP_MEMORY_LIMIT" ]; then
|
||||||
errecho 'clip exceeds memory threshold! not caching...'
|
notify 'clip exceeds memory threshold! not caching...'
|
||||||
exists notify-send && notify-send 'clip exceeds memory threshold! not caching...'
|
|
||||||
rm -f "$BUFFER"
|
rm -f "$BUFFER"
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
|
@ -141,7 +139,7 @@ updateclip() {
|
||||||
# apply text filters
|
# apply text filters
|
||||||
[ -n "$SHCLIP_FILTER_ENABLED" ] && [ -f "$SHCLIP_CONFIG_DIR/filter.sh" ] && \
|
[ -n "$SHCLIP_FILTER_ENABLED" ] && [ -f "$SHCLIP_CONFIG_DIR/filter.sh" ] && \
|
||||||
sh "$SHCLIP_CONFIG_DIR/filter.sh" < "$BUFFER" | diff "$BUFFER" - | patch "$BUFFER"
|
sh "$SHCLIP_CONFIG_DIR/filter.sh" < "$BUFFER" | diff "$BUFFER" - | patch "$BUFFER"
|
||||||
xclip -sel clipboard "$BUFFER"
|
xclip -sel clipboard "$BUFFER"
|
||||||
[ -n "$SHCLIP_SYNC_CLIPBOARD" ] && xclip -sel primary "$BUFFER"
|
[ -n "$SHCLIP_SYNC_CLIPBOARD" ] && xclip -sel primary "$BUFFER"
|
||||||
;;
|
;;
|
||||||
*) ;;
|
*) ;;
|
||||||
|
@ -166,16 +164,34 @@ updateclip() {
|
||||||
[ -z "${DISPLAY:-}" ] && fail 'Cannot find $DISPLAY. Is your X server running?'
|
[ -z "${DISPLAY:-}" ] && fail 'Cannot find $DISPLAY. Is your X server running?'
|
||||||
|
|
||||||
# parse options
|
# parse options
|
||||||
while getopts :pnf OPT; do
|
while getopts :hn:f:s:p:c:m OPT; do
|
||||||
case $OPT in
|
case $OPT in
|
||||||
n) SHCLIP_ENABLED="" ;;
|
h) cat >&2 <<-EOF
|
||||||
f) SHCLIP_FILTER_ENABLED=1 ;;
|
please refer to README for general usage:
|
||||||
|
https://git.unix.dog/yosh/shclip
|
||||||
|
|
||||||
|
options that exist (overrides config file):
|
||||||
|
-h show this help
|
||||||
|
-n <on|off> enable/disable shclip on startup
|
||||||
|
-f <on|off> enable/disable filtering
|
||||||
|
-s <on|off> enable/disable syncing clipboard to primary
|
||||||
|
-p <on|off> enable/disable caching kde passwords
|
||||||
|
-c <num> set max clips to <num> clips
|
||||||
|
-m <num> set memory limit to <num> kibibytes
|
||||||
|
EOF
|
||||||
|
;;
|
||||||
|
n) [ "$OPTARG" = "on" ] && SHCLIP_ENABLED=1 || SHCLIP_ENABLED="" ;;
|
||||||
|
f) [ "$OPTARG" = "on" ] && SHCLIP_FILTER_ENABLED=1 || SHCLIP_FILTER_ENABLED="" ;;
|
||||||
|
s) [ "$OPTARG" = "on" ] && SHCLIP_SYNC_CLIPBOARD=1 || SHCLIP_SYNC_CLIPBOARD="" ;;
|
||||||
|
p) [ "$OPTARG" = "on" ] && SHCLIP_CACHE_PASSWORDS=1 || SHCLIP_CACHE_PASSWORDS="" ;;
|
||||||
|
c) SHCLIP_MAX_CLIPS=$OPTARG ;;
|
||||||
|
m) SHCLIP_MEMORY_LIMIT=$OPTARG ;;
|
||||||
*) fail "$BN: unknown option: -$OPTARG" ;;
|
*) fail "$BN: unknown option: -$OPTARG" ;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
setup
|
setup
|
||||||
while
|
while
|
||||||
if [ -z "$SHCLIP_ENABLED" ]; then
|
if [ -z "$SHCLIP_ENABLED" ]; then
|
||||||
:
|
:
|
||||||
else
|
else
|
||||||
|
|
Loading…
Reference in New Issue