Ledger Nano X - The secure hardware wallet
SHARE
TWEET

Untitled

a guest Mar 24th, 2020 64 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/env bash
  2. #
  3. # ScreenCAP Helper - a single simple interface for various screenshot utils.
  4.  
  5. # set -x
  6. set -Eeuo pipefail
  7. readonly PROGNAME=$(basename "$0")
  8.  
  9. # CONFIG
  10. readonly SCAPH_FILENAME_TEMPLATE=${SCAPH_FILENAME_TEMPLATE:-'Screenshot_%Y%m%d_%H%M%S'}
  11. readonly SCAPH_FILENAME=${SCAPH_FILENAME:-$(date +"$SCAPH_FILENAME_TEMPLATE")}
  12. readonly SCAPH_SAVEFOLDER=${SCAPH_SAVEFOLDER:-${XDG_PICTURES_DIR:=HOME/Pictures}/Screenshots}
  13. readonly SCAPH_CMDS=${SCAPH_CMDS:-'spectacle
  14. scrot
  15. maim'}
  16.  
  17. help() {
  18.     echo "usage: $PROGNAME [OPTION]
  19.  
  20. ScreenCAP Helper - simple common interface for various screenshot utils.
  21.  
  22. OPTIONS
  23.     -h, --help                  show this help
  24.     -f, --fullscreen            screenshot fullscreen
  25.     -d, --display               screenshot current display
  26.     -a, --active                screenshot active window
  27.     -r, --region                screenshot region
  28.     -u, --under-cursor          screenshot under cursor
  29.     -t, --transient             screenshot transient
  30.  
  31. Screenshots are saved to \$SCAPH_SAVEFOLDER (${SCAPH_SAVEFOLDER/#$HOME/\~}).
  32. If xclip is available, they're also copied to clipboard.
  33. "
  34. }
  35.  
  36. main() {
  37.     local format=png
  38.  
  39.     # find command
  40.     for cmd in $SCAPH_CMDS; do
  41.         if command -v "$cmd" &>/dev/null; then
  42.             CMD=$cmd
  43.             break
  44.         fi
  45.     done
  46.     # find folder
  47.     local savefolder=$SCAPH_SAVEFOLDER
  48.     while [ ! -d "$savefolder" ]; do
  49.         savefolder=$(dirname "$savefolder")
  50.     done
  51.     local filename=${savefolder}/${SCAPH_FILENAME}.${format}
  52.  
  53.     local arg=${1:-}
  54.     case "$arg" in
  55.     -h | --help) help && exit 0 ;;
  56.     -f | --fullscreen | '')
  57.         spectacle_args=(-f)
  58.         maim_args=(-i)
  59.         scrot_args=(-m)
  60.         ;;
  61.     -d | --display)
  62.         spectacle_args=(-m)
  63.         maim_args=(-i) # todo
  64.         scrot_args=()
  65.         ;;
  66.     -a | --active)
  67.         spectacle_args=(-a)
  68.         maim_args=(-i "$(xdotool getactivewindow)")
  69.         scrot_args=(-u -b)
  70.         ;;
  71.     -r | --region)
  72.         spectacle_args=(-r)
  73.         maim_args=(-s)
  74.         scrot_args=(-s -f)
  75.         ;;
  76.     -u | --under-cursor)
  77.         spectacle_args=(-u)
  78.         maim_args=(-i "$(xdotool getactivewindow)") # todo
  79.         scrot_args=(-u -b)                          # todo
  80.         ;;
  81.     -t | --transient)
  82.         spectacle_args=(-t)
  83.         maim_args=(-i "$(xdotool getactivewindow)") # todo
  84.         scrot_args=(-u)                             # todo
  85.         ;;
  86.     *) help && exit 1 ;;
  87.     esac
  88.  
  89.     # screenshot
  90.     case "$CMD" in
  91.     spectacle) spectacle -b "${spectacle_args[@]}" -o "$filename" &;;
  92.     maim) maim "${maim_args[@]}" "$filename" ;;
  93.     scrot) scrot "${scrot_args[@]}" "$filename" ;;
  94.     *) exit 1 ;;
  95.     esac
  96.  
  97.     if command -v 'xclip' &>/dev/null; then
  98.         sleep 0.5
  99.         xclip -selection clipboard -t "image/$format" -i "$filename"
  100.     fi
  101. }
  102.  
  103. main "$@"
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top