From 3e25e0fd8d376a782d07f55921f3b3cc81500d95 Mon Sep 17 00:00:00 2001 From: Andrew Date: Tue, 28 Jan 2025 04:30:13 +0000 Subject: [PATCH] [vimshot.sh]: Merge x11_vimshot.sh and wl_vimshot.sh --- README.md | 3 +-- src/{wl_vimshot.sh => vimshot.sh} | 14 +++++++++++--- src/x11_vimshot.sh | 16 ---------------- 3 files changed, 12 insertions(+), 21 deletions(-) rename src/{wl_vimshot.sh => vimshot.sh} (60%) mode change 100755 => 100644 delete mode 100755 src/x11_vimshot.sh diff --git a/README.md b/README.md index 754364e..6dbfa9b 100644 --- a/README.md +++ b/README.md @@ -34,8 +34,7 @@ - `stopwatch.sh`: simple stopwatch script that counts the elapsed time in seconds, and displays it in the format HH:MM:SS. - `sync_music.sh`: script to sync my Android phone's music library to the contents of my `~/media/music/` directory, i.e. copy my music library from my laptop to my phone. + - `vimshot.sh`: script to take a wait a few seconds before taking a screenshot to the filepath in the clipboard, for use as part of my LaTeX note-taking workflow in Vim: create the figure environment, copy the file name, invoke this script, and select the region in the source material to be screenshotted. - `webcam.sh`: one-line script that uses the video viewer program `mpv` as a webcam by using `/dev/video0` as its video file source. - `wifi_dmenu.sh`: script to connect to an available WiFi network with a dmenu prompt. - - `wl_vimshot.sh`: Wayland script to take a wait a few seconds before taking a screenshot to the filepath in the clipboard, for use as part of my LaTeX note-taking workflow in Vim: create the figure environment, copy the file name, invoke this script, and select the region in the source material to be screenshotted. of the screenshot via `notify-send`. - - `x11_vimshot.sh`: X11 script to take a wait a few seconds before taking a screenshot to the filepath in the clipboard, for use as part of my LaTeX note-taking workflow in Vim: create the figure environment, copy the file name, invoke this script, and select the region in the source material to be screenshotted. diff --git a/src/wl_vimshot.sh b/src/vimshot.sh old mode 100755 new mode 100644 similarity index 60% rename from src/wl_vimshot.sh rename to src/vimshot.sh index 53cfd45..ffe0625 --- a/src/wl_vimshot.sh +++ b/src/vimshot.sh @@ -3,7 +3,12 @@ # For use as part of my LaTeX note-taking workflow in Vim: create the figure environment, copy the file name, invoke this script, and select the region in the source material to be screenshotted. basename=$(basename "$0") -filepath=$(wl-paste) + +if [ $(pgrep -x "Xorg") ]; then + filepath=$(xclip -selection clipboard -out) +else + filepath=$(wl-paste) +fi # check if the filepath is absolute or relative, and if relative, make absolute if [ "${filepath#\/}" = "$filepath" ] || [ "${filepath#\~}" = "$filepath" ]; then @@ -13,6 +18,9 @@ fi notify-send "$basename" "Taking screenshot to $filepath" sleep 5 -grim -g "$(slurp)" "$filepath" -notify-send --icon "$filepath" "$basename" "Screenshot saved to: $filepath" +if [ $(pgrep -x "Xorg") ]; then + maim --select --hidecursor "$filepath" && notify-send --icon "$filepath" "$basename" "Screenshot saved to: $filepath" +else + grim -g "$(slurp)" "$filepath" && notify-send --icon "$filepath" "$basename" "Screenshot saved to: $filepath" +fi diff --git a/src/x11_vimshot.sh b/src/x11_vimshot.sh deleted file mode 100755 index 7a80618..0000000 --- a/src/x11_vimshot.sh +++ /dev/null @@ -1,16 +0,0 @@ -#!/bin/sh -# Script to take a wait a few seconds before taking a screenshot to the filepath in the clipboard. -# For use as part of my LaTeX note-taking workflow in Vim: create the figure environment, copy the file name, invoke this script, and select the region in the source material to be screenshotted. - -basename=$(basename "$0") -filepath=$(xclip -selection clipboard -out) - -# check if the filepath is absolute or relative, and if relative, make absolute -if [ "${filepath#\/}" = "$filepath" ] || [ "${filepath#\~}" = "$filepath" ]; then - filepath="$(pwd)/$filepath" -fi - -notify-send "$basename" "Taking screenshot to $filepath" - -sleep 5 -maim --select --hidecursor "$filepath" && notify-send --icon "$filepath" "$basename" "Screenshot saved to: $filepath"