diff options
author | Tom Ryder <tom@sanctum.geek.nz> | 2024-11-17 16:06:01 +1300 |
---|---|---|
committer | Tom Ryder <tom@sanctum.geek.nz> | 2024-11-17 16:06:01 +1300 |
commit | 246aca0762727db45a4a0bf1b12297c937551930 (patch) | |
tree | 0b5b4e819aed7f79737c5dec0e3199eb0c75a08a | |
download | vixf-246aca0762727db45a4a0bf1b12297c937551930.tar.gz vixf-246aca0762727db45a4a0bf1b12297c937551930.zip |
First development version: Bash prototype
Just committing this for reference; about to attempt a Python rewrite.
-rw-r--r-- | i3.config | 5 | ||||
-rw-r--r-- | sxhkdrc | 2 | ||||
-rw-r--r-- | vixf.bash | 40 |
3 files changed, 47 insertions, 0 deletions
diff --git a/i3.config b/i3.config new file mode 100644 index 0000000..0f3fcdc --- /dev/null +++ b/i3.config @@ -0,0 +1,5 @@ +# Key binding (see also: sxhkdrc) +bindsym Mod4+grave exec vixf + +# Make vixf terminal windows floating +for_window [class="XTerm" instance="vixf"] floating enable @@ -0,0 +1,2 @@ +super + grave + vixf diff --git a/vixf.bash b/vixf.bash new file mode 100644 index 0000000..fa49a51 --- /dev/null +++ b/vixf.bash @@ -0,0 +1,40 @@ +#!bash +# We use Bash for a more reliable EXIT trap. + +# Name this script (and its xterm instance). +self=vixf + +# We leave a little bit of time for window focus etc to switch around. +refocus=0.5 + +# Create a temporary directory with name in $tempdir, and handle POSIX-ish traps to +# remove it when the script exits. +tempdir= +cleanup() { + rm --force --recursive -- "$tempdir" +} +trap cleanup EXIT +tempdir=$(mktemp --directory) + +# After a short delay for the window manager to finish re-focussing windows, +# then select everything in the field and copy it. +xdotool \ + sleep "$refocus" \ + key --clearmodifiers -- ctrl+a ctrl+c || exit + +# Write the clipboard contents to the temporary file. +xsel --clipboard --output > "$tempdir"/vixf || exit + +# Fire up a terminal emulator with $VISUAL, or vi(1) if not set +x-terminal-emulator \ + -name "$self" \ + -e "${VISUAL:-vi}" "$tempdir"/vixf || exit + +# Read the modified file into the clipboard +xsel --clipboard --input < "$tempdir"/vixf || exit + +# After another short delay, paste the modified text over the original, which +# should still be selected +xdotool \ + sleep "$refocus" \ + key --clearmodifiers -- ctrl+v || exit |