sh: Reintegrate clip script
Brought back an old universal clipping script and updated it to work better - well, at all. Can now decide between wl-copy, xclip and xsel and will do so in that order. Can take clipping material from the following arguments (will clip any and all following arguments) or from stdin. Stdin has precedence. Not much more to say really, but makes writing other applications a bit more universal when they rely on this universal little tool.
This commit is contained in:
parent
ff78a1f32f
commit
94cd954df9
3 changed files with 89 additions and 46 deletions
42
sh/.local/bin/clip
Executable file
42
sh/.local/bin/clip
Executable file
|
@ -0,0 +1,42 @@
|
|||
#!/usr/bin/env sh
|
||||
|
||||
# clip -- easy copying to clipboard manager with
|
||||
# wl-copy / xclip / xsel
|
||||
#
|
||||
# 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
|
||||
|
||||
clip() {
|
||||
if exist wl-copy; then
|
||||
printf "%s" "$1" | wl-copy
|
||||
elif exist xclip; then
|
||||
echo "$1" | xclip -i -selection clipboard
|
||||
elif exist xsel; then
|
||||
echo "$1" | xsel -i --clipboard
|
||||
else
|
||||
printf "No working clipboard program found. Install wl-copy/xclip/xsel and try again."
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
# if we are in a pipe, read from stdin
|
||||
if [ ! -t 0 ]; then
|
||||
clip "$(cat /dev/stdin)"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# TODO check if $1 is a file, and if it's png or similar, clip that
|
||||
|
||||
if [ $# -lt 1 ]; then
|
||||
printf "No file argument or stdin passed to clip. Exiting."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ "$#" -ge 1 ]; then
|
||||
clip "$*"
|
||||
exit 0
|
||||
fi
|
|
@ -225,16 +225,17 @@ nnoremap e :!nvim %f<cr>
|
|||
nnoremap gb :file &<cr>l
|
||||
|
||||
" yank current directory path into the clipboard
|
||||
nnoremap yd :!echo -n %d | xclip -selection "clipboard" %i<cr>
|
||||
" clip is universal clipper from `sh` module
|
||||
nnoremap yd :!echo -n %d | clip %i<cr>
|
||||
|
||||
" yank current file path into the clipboard
|
||||
nnoremap yf :!echo -n %c:p | xclip -selection "clipboard" %i<cr>
|
||||
nnoremap yf :!echo -n %c:p | clip %i<cr>
|
||||
|
||||
" yank current filename without path into the clipboard
|
||||
nnoremap yt :!echo -n %c | xclip -selection "clipboard" %i<cr>
|
||||
nnoremap yt :!echo -n %c | clip %i<cr>
|
||||
|
||||
" yank root of current file's name into the clipboard
|
||||
nnoremap yr :!echo -n %c:r | xclip -selection "clipboard" %i<cr>
|
||||
nnoremap yr :!echo -n %c:r | clip %i<cr>
|
||||
|
||||
" Mappings for faster renaming
|
||||
nnoremap I cw<c-a>
|
||||
|
|
Loading…
Reference in a new issue