dotfiles

My personal shell configs and stuff
git clone git://git.alex.balgavy.eu/dotfiles.git
Log | Files | Refs | Submodules | README | LICENSE

ss-interceptor (1454B)


      1 #!/usr/bin/env bash
      2 
      3 # Preliminary tests
      4 if [[ $(uname -s) == "Darwin" ]]; then
      5   ss_dir_orig="$(defaults read com.apple.screencapture location)"
      6 elif [[ $(uname -s) == "Linux" ]] && command -v gsettings &> /dev/null; then
      7   ss_dir_orig="$(gsettings get org.gnome.gnome-screenshot auto-save-directory)"  
      8 else
      9   echo "Not supported on this system."
     10   exit 1
     11 fi
     12 
     13 if [ $# -eq 0 ]; then
     14   echo "Need a new directory!"
     15   echo "Usage:"
     16   echo "ss-interceptor [NEW_LOCATION]"
     17   exit 1
     18 fi
     19 
     20 cleanup() {
     21   echo "..."
     22   echo "Done. Screenshots saved to $new_ss_dir."
     23   if [[ $(uname -s) == "Darwin" ]]; then
     24     defaults write com.apple.screencapture location "$ss_dir_orig"
     25   elif [[ $(uname -s) == "Linux" ]]; then
     26     gsettings set org.gnome.gnome-screenshot auto-save-directory "$ss_dir_orig"
     27   fi
     28   exit 0
     29 }
     30 
     31 trap cleanup exit
     32 
     33 echo "= Screenshot Interceptor ="
     34 
     35 if [ "${1:0:1}" = "." ]; then
     36   new_ss_dir="$(pwd)/${1#*/}"
     37 elif [ "${1:0:1}" != "/" ]; then
     38   new_ss_dir="$(pwd)/$1"
     39 else
     40   new_ss_dir="$1"
     41 fi
     42 
     43 
     44 if ! [ -d "$new_ss_dir" ]; then
     45   echo "Creating $new_ss_dir..."
     46   mkdir -p "$new_ss_dir"
     47 fi
     48 
     49 if [[ $(uname -s) == "Darwin" ]]; then
     50   defaults write com.apple.screencapture location "$new_ss_dir"
     51 elif [[ $(uname -s) == "Linux" ]]; then
     52   gsettings set org.gnome.gnome-screenshot auto-save-directory "$new_ss_dir"
     53 else
     54   echo "Error"
     55 fi
     56 
     57 echo "Saving screenshots to:"
     58 echo "$new_ss_dir"
     59 echo -e "\nPress Ctrl-C to stop..."
     60 
     61 while :; do sleep 1; done