From 2fcc9ad27c5f2d8ca58df22eb7f9920c634b279c Mon Sep 17 00:00:00 2001 From: Andrew Cady Date: Tue, 14 Sep 2021 02:01:26 -0400 Subject: cutbuffer stack feature partially implemented --- dot/local/bin/cutbuffer_pop | 81 ++++++++++++++++++++++++++++++++++++++++++++ dot/local/bin/cutbuffer_push | 68 +++++++++++++++++++++++++++++++++++++ dot/xbindkeysrc | 6 ++++ 3 files changed, 155 insertions(+) create mode 100755 dot/local/bin/cutbuffer_pop create mode 100755 dot/local/bin/cutbuffer_push diff --git a/dot/local/bin/cutbuffer_pop b/dot/local/bin/cutbuffer_pop new file mode 100755 index 0000000..6b314e5 --- /dev/null +++ b/dot/local/bin/cutbuffer_pop @@ -0,0 +1,81 @@ +#!/bin/sh + +# A screen-grab will be saved in $SCREEN_GRAB_DEST_DIR if set, otherwise +# in $HOME/screen_grab/ if it exsts; otherwise $HOME. + +default_basename=cutbuffer_grab +default_extension=txt +date_format=+%F_%H%M%S +SCREEN_GRAB_DEST_DIR=$HOME/$default_basename + +chdir_to_destination() +{ + [ -d "$SCREEN_GRAB_DEST_DIR" ] || mkdir -p "$SCREEN_GRAB_DEST_DIR" + cd "$SCREEN_GRAB_DEST_DIR" +} + +choose_destination() +{ + local stamp basename extension now + case $# in + 1) ;; + 0) now=$(date "$date_format") + DESTINATION=$default_basename.$now.$default_extension + return + ;; + *) return 1 ;; + esac + + case "$1" in + *.*) + basename=${1%.*} + extension=${1##*.} + ;; + *) + basename=$1 + extension=$default_extension + ;; + esac + DESTINATION=$basename.$extension +} + +get_out_the_way() +{ + local stamp basename extension destination + [ -e "$1" ] || return 0 + + stamp=$(date -r "$1" "$date_format") || return + case "$1" in + *.*) + basename=${1%.*} + extension=${1##*.} + destination=$basename.$stamp.$extension + ;; + *) + destination=$1.$stamp + ;; + esac + [ ! -e "$destination" ] || return + mv "$1" "$destination" +} + +extract() +{ + sort -z -k1,1 -r | head -z -n 1 | xargs -0 printf '%s\n' | cut -d' ' -f2 +} + + +set -e + +chdir_to_destination + +f=$(find . -maxdepth 1 -type f -printf "%C@ %h/%f\0" | extract) + +set -x +exec 2> /tmp/cbp.log + +xcb -s 0 < "$f" +xcb -p 0 | xsel +mkdir -p .popped +mv "$f" -t .popped + diff --git a/dot/local/bin/cutbuffer_push b/dot/local/bin/cutbuffer_push new file mode 100755 index 0000000..f7e1e69 --- /dev/null +++ b/dot/local/bin/cutbuffer_push @@ -0,0 +1,68 @@ +#!/bin/sh + +# A screen-grab will be saved in $SCREEN_GRAB_DEST_DIR if set, otherwise +# in $HOME/screen_grab/ if it exsts; otherwise $HOME. + +default_basename=cutbuffer_grab +default_extension=txt +date_format=+%F_%H%M%S +SCREEN_GRAB_DEST_DIR=$HOME/$default_basename + +chdir_to_destination() +{ + [ -d "$SCREEN_GRAB_DEST_DIR" ] || mkdir -p "$SCREEN_GRAB_DEST_DIR" + cd "$SCREEN_GRAB_DEST_DIR" +} + +choose_destination() +{ + local stamp basename extension now + case $# in + 1) ;; + 0) now=$(date "$date_format") + DESTINATION=$default_basename.$now.$default_extension + return + ;; + *) return 1 ;; + esac + + case "$1" in + *.*) + basename=${1%.*} + extension=${1##*.} + ;; + *) + basename=$1 + extension=$default_extension + ;; + esac + DESTINATION=$basename.$extension +} + +get_out_the_way() +{ + local stamp basename extension destination + [ -e "$1" ] || return 0 + + stamp=$(date -r "$1" "$date_format") || return + case "$1" in + *.*) + basename=${1%.*} + extension=${1##*.} + destination=$basename.$stamp.$extension + ;; + *) + destination=$1.$stamp + ;; + esac + [ ! -e "$destination" ] || return + mv "$1" "$destination" +} + +set -e + +chdir_to_destination +choose_destination "$@" +get_out_the_way "$DESTINATION" +xcb -p 0 > "$DESTINATION" + diff --git a/dot/xbindkeysrc b/dot/xbindkeysrc index 2ddcd5b..ec4eb9d 100644 --- a/dot/xbindkeysrc +++ b/dot/xbindkeysrc @@ -78,6 +78,12 @@ control + XF86AudioLowerVolume "im" Print +"cutbuffer_push" + control + Print + +"cutbuffer_pop" + alt + Print + "scrolltoggle" Scroll_Lock -- cgit v1.2.3