diff options
| author | Charles Cabergs <me@cacharle.xyz> | 2024-10-26 18:49:12 +0200 |
|---|---|---|
| committer | Charles Cabergs <me@cacharle.xyz> | 2024-10-26 18:49:12 +0200 |
| commit | 90df8624a43c440ffa77c02f74f4ef1cb27a6648 (patch) | |
| tree | 394f91cacb4976a4f9fe67326076ea7ebd5adc4d /local | |
| parent | 5c4886cf068d44a75978aead81a4bdc3afad66cc (diff) | |
| download | dotfiles-90df8624a43c440ffa77c02f74f4ef1cb27a6648.tar.gz dotfiles-90df8624a43c440ffa77c02f74f4ef1cb27a6648.tar.bz2 dotfiles-90df8624a43c440ffa77c02f74f4ef1cb27a6648.zip | |
Update screenshot script to have window capture and file size optimization
Diffstat (limited to 'local')
| -rwxr-xr-x | local/bin/screenshot-prompt | 38 |
1 files changed, 31 insertions, 7 deletions
diff --git a/local/bin/screenshot-prompt b/local/bin/screenshot-prompt index 27a4fce..6852eba 100755 --- a/local/bin/screenshot-prompt +++ b/local/bin/screenshot-prompt @@ -12,6 +12,8 @@ choice="$( $menu_exec <<EOF Crop to clipboard Crop to file +Window to clipboard +Window to file Fullscreen to clipboard Fullscreen to file EOF @@ -19,19 +21,41 @@ EOF screenshot_dir="$HOME/screenshots" [ ! -d "$screenshot_dir" ] && mkdir "$screenshot_dir" -file_format="$screenshot_dir/"'%Y-%m-%d_$wx$h.png' + +scrot_wrapper() { + file_format="$screenshot_dir/"'%Y-%m-%d_$wx$h.png' + if [ "$1" = '-' ] + then + file_format='-' # Keep stdout if not saving to a file + shift + else + # optipng optimizes png size without loss (doesn't work if we output directly to stdout) + command -v optipng && optipng_arg='optipng -o4 $f' + fi + scrot --silent --quality 95 --compression 9 --file "$file_format" -e "$optipng_arg" "$@" +} + +xclip_wrapper() { + xclip -selection clipboard -target image/png +} case "$choice" in + 'Crop to clipboard') + scrot_wrapper - --select | xclip_wrapper + ;; 'Crop to file') - scrot --select --silent --file "$file_format" + scrot_wrapper --select ;; - 'Crop to clipboard') - scrot --select --silent - | xclip -selection clipboard -target image/png + 'Window to clipboard') + scrot_wrapper - --window "$(xdo id -p PID)" | xclip_wrapper ;; - 'Fullscreen to file') - scrot --silent --file "$file_format" + 'Window to file') + scrot_wrapper --window "$(xdo id -p PID)" ;; 'Fullscreen to clipboard') - scrot --silent - | xclip -selection clipboard -target image/png + scrot_wrapper - | xclip_wrapper + ;; + 'Fullscreen to file') + scrot_wrapper ;; esac |
