123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- #!/bin/bash
-
- . $(ffoom path)
-
- ffoo import config
- ffoo import pretty
-
- STORAGE_DIR="$HOME/.local/share/saturnin/clips"
-
- usage() {
- usage_is "save [-1|-2|-c]"
- usage_is "load [-1|-2|-c] name"
- }
-
- clipln() {
- #
- # Print desired clipboard(s) and \n
- #
- case $1 in
- primary|secondary|clipboard)
- xclip -o -selection $1 2>/dev/null
- ;;
- ALL)
- xclip -o -selection primary 2>/dev/null
- xclip -o -selection secondary 2>/dev/null
- xclip -o -selection clipboard 2>/dev/null
- ;;
- esac
- echo ""
- }
-
- save_clip() {
- local clipname=$1
- mkdir -p "$STORAGE_DIR" || die "could not create directory for saving"
- local path="$STORAGE_DIR/$(date +%Y%m%d-%H%M%S.clip)"
- clipln $clipname > "$path"
- }
-
- lsclips() {
- local clipname=$1
- local ft hint name
- test -d "$STORAGE_DIR" || return 0
- ls "$STORAGE_DIR/"*.clip 2>/dev/null \
- | while read name;
- do
- ft=$(file -b -i $name | cut -d\; -f1)
- case $ft in
- text/*)
- hint=$(head -c 80 $name | tr '\n' '↵')
- ;;
- *)
- hint=$(head -c 16 $name | hexdump -C)
- ;;
- esac
- echos "$(basename $name) || $ft || $hint"
- done
- }
-
- load_clip() {
- local clipname=$1
- local fname=$(saturnin clip ls | saturnin dmenu | cut -d\ -f 1)
- cat $STORAGE_DIR/$name | xclip -i -selection $clipname
- }
-
- clipname=primary
- action=ls
- while true; do case "$1" in
- save) action=save; shift ;;
- load) action=load; shift ;;
- ls) action=list; shift ;;
- -1) clipname=primary; shift ;;
- -2) clipname=secondary; shift ;;
- -c) clipname=clipboard; shift ;;
- "") break; ;;
- *) usage; ;;
- esac done
-
- debug "\$@='$@'"
- debug -v clipname action
-
- case $action in
- save) save_clip $clipname ;;
- load) load_clip $clipname ;;
- list) lsclips ;;
- esac
-
|