[X] Add simplifying xclip script
Added `clip` to path, allows sending stuff through stdin or via normal file input to xclip. Makes xclip default to clipboard when clipping input. Special handlers for image files (png and jp[e]g).
This commit is contained in:
parent
0f67355ccd
commit
e5a6c3e350
1 changed files with 36 additions and 0 deletions
36
xresources/.local/bin/clip
Executable file
36
xresources/.local/bin/clip
Executable file
|
@ -0,0 +1,36 @@
|
||||||
|
#!/usr/bin/env sh
|
||||||
|
|
||||||
|
# clip -- easy copying to x clipboard manager with xclip
|
||||||
|
#
|
||||||
|
# clips the first argument to the clipboard
|
||||||
|
# or stdin if stdin is passed
|
||||||
|
# will copy png/jpg as image files
|
||||||
|
#
|
||||||
|
# idea ~~stolen~~ creatively borrowed from
|
||||||
|
# https://github.com/kyazdani42/dotfiles/blob/master/bin/copy
|
||||||
|
|
||||||
|
if ! exist xclip normal; then exit 1; fi
|
||||||
|
|
||||||
|
# if we are in a pipe, read from stdin
|
||||||
|
if [ ! -t 0 ]; then
|
||||||
|
xclip -i -selection clipboard /dev/stdin
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ $# != 1 ] || [ ! -f "$1" ]; then
|
||||||
|
printf "No file argument passed to xclip to clip: %s" "$1"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
options=""
|
||||||
|
if grep -qE '.png$' "$1"; then
|
||||||
|
options="-target image/png"
|
||||||
|
elif grep -qE '.jpe\?g$' "$1"; then
|
||||||
|
options="-target image/jpeg"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -n "$options" ]; then
|
||||||
|
xclip -selection clipboard "$options" "$1"
|
||||||
|
else
|
||||||
|
xclip -selection clipboard "$1"
|
||||||
|
fi
|
Loading…
Reference in a new issue