Restructuring the repo
This commit is contained in:
parent
21e3cf65e6
commit
3d67598c27
45 changed files with 368 additions and 77 deletions
84
misc/xc
Executable file
84
misc/xc
Executable file
|
@ -0,0 +1,84 @@
|
|||
#!/bin/zsh
|
||||
|
||||
# install this program with the name xc and symlink it as xs.
|
||||
# xc will use the clipboard selection, while xs while use the primary selection
|
||||
|
||||
source ${$(realpath "$0"):h:h}/lib/common.zsh
|
||||
depend xclip
|
||||
|
||||
function get_primary() { xclip -o -selection primary }
|
||||
function get_clipboard() { xclip -o -selection clipboard }
|
||||
function set_primary() { xclip -i -selection primary }
|
||||
function set_clipboard() { xclip -i -selection clipboard }
|
||||
function show_both() {
|
||||
printf "\e[1;94mPrimary\e[0m\n"
|
||||
get_primary
|
||||
echo
|
||||
printf "\e[1;94mClipboard\e[0m\n"
|
||||
get_clipboard
|
||||
}
|
||||
|
||||
function read_both() {
|
||||
depend pee
|
||||
pee "xclip -i -selection primary" "xclip -i -selection clipboard"
|
||||
}
|
||||
|
||||
function common() {
|
||||
cmd=$1
|
||||
getc=$2
|
||||
setc=$3
|
||||
shift 3
|
||||
case "$cmd" in
|
||||
"read") $setc;;
|
||||
"clear") echo -n | $setc;;
|
||||
"readboth") read_both ;;
|
||||
"showboth") show_both ;;
|
||||
"sed") $getc | sed -e "$@" | $setc; $getc;;
|
||||
"pipe") $getc | "$@" | $setc; $getc;;
|
||||
"edit") depend vipe; $getc | vipe | $setc; $getc;;
|
||||
"") if [[ -t 0 ]]; then $getc; else $setc; fi;;
|
||||
*) <<-HELP
|
||||
Usage: xc [COMMAND]
|
||||
xc fromxs|toxs
|
||||
xs [COMMAND]
|
||||
xs fromxc|toxc
|
||||
|
||||
The used X selection is determined by the name the program is called as:
|
||||
xc: clipboard (Ctrl-C / Ctrl-V)
|
||||
xs: primary selection (middle mouse button)
|
||||
For showboth/readboth, the action is done for both selections.
|
||||
|
||||
Commands:
|
||||
show/showboth: show contents of clipboard (default if no command given)
|
||||
read/readboth: store input to clipboard (default if stdin is not a terminal)
|
||||
sed: modify contents using a sed expression
|
||||
pipe: modify contents by piping through a command
|
||||
edit: edit clipboard contents using \$EDITOR
|
||||
|
||||
fromxs/toxs: xc only: copy contents from or to primary selection
|
||||
fromxc/toxc: xs only: copy contents from or to clipboard
|
||||
HELP
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
cmd=$1
|
||||
[[ -n $1 ]] && shift
|
||||
|
||||
case "${0:t}" in
|
||||
xc)
|
||||
case "$cmd" in
|
||||
"fromxs"|"fromXS") get_primary | set_clipboard ;;
|
||||
"toxs"|"toXS") get_clipboard | set_primary ;;
|
||||
*) common "$cmd" get_clipboard set_clipboard "$@";;
|
||||
esac
|
||||
;;
|
||||
xs)
|
||||
case "$cmd" in
|
||||
"fromxc"|"fromXC") get_clipboard | set_primary ;;
|
||||
"toxc"|"toXC") get_primary | set_clipboard ;;
|
||||
*) common "$cmd" get_primary set_primary "$@";;
|
||||
esac
|
||||
;;
|
||||
esac
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue