this repo has no description
dotfiles

Update sharpshot utility

The task of watching for the screenshot file being created in /tmp
has been moved to its own script (basically only contains the call
to inotifywait).

The sharpshot bin is now only a helper to call spectacle and put the
screenshot in /tmp with the pre-defined filename.

+9 -38
+9 -38
bin/sharpshot
··· 9 9 NAME='sharpshot' 10 10 SELF="${0:-$NAME}" 11 11 VERSION='0.0.1' 12 - OUTPUT_FILE="${SHARPSHOT_OUTPUT_FILE:-/tmp/sharpshot.png}" 13 - COMMAND="${SHARPSHOT_COMMAND:-spectacle -b -o \"${OUTPUT_FILE}\"}" 14 - COPY_COMMAND="${SHARPSHOT_COPY_COMMAND:-wl-copy}" 15 - FULL_SWITCH="${SHARPSHOT_FULL_SWITCH:--f}" 16 - ACTIVE_SWITCH="${SHARPSHOT_ACTIVE_SWITCH:--a}" 17 - REGION_SWITCH="${SHARPSHOT_REGION_SWITCH:--r}" 12 + OUTPUT_FILE=${SHARPSHOT_OUTPUT_FILE:-/tmp/sharpshot.png} 13 + COMMAND=${SHARPSHOT_COMMAND:-spectacle -b -o ${OUTPUT_FILE}} 14 + COPY_COMMAND=${SHARPSHOT_COPY_COMMAND:-wl-copy} 15 + FULL_SWITCH=${SHARPSHOT_FULL_SWITCH:--f} 16 + ACTIVE_SWITCH=${SHARPSHOT_ACTIVE_SWITCH:--a} 17 + REGION_SWITCH=${SHARPSHOT_REGION_SWITCH:--r} 18 18 VERBOSE=false 19 19 DRY=false 20 20 ··· 29 29 if $DRY; then 30 30 echo "DRY-RUN, would execute: '$COMMAND $FULL_SWITCH'" 31 31 else 32 - "$COMMAND" "$FULL_SWITCH" 32 + $COMMAND "$FULL_SWITCH" & 33 33 fi 34 34 } 35 35 ··· 38 38 if $DRY; then 39 39 echo "DRY-RUN, would execute: '$COMMAND $ACTIVE_SWITCH'" 40 40 else 41 - "$COMMAND" "$ACTIVE_SWITCH" 41 + $COMMAND "$ACTIVE_SWITCH" & 42 42 fi 43 43 } 44 44 ··· 47 47 if $DRY; then 48 48 echo "DRY-RUN, would execute: '$COMMAND $REGION_SWITCH'" 49 49 else 50 - "$COMMAND" "$REGION_SWITCH" 51 - fi 52 - } 53 - 54 - copy() { 55 - verbose 'Copying result file to clipboard' 56 - if $DRY; then 57 - echo "DRY-RUN, would execute: '$COPY_COMMAND < $OUTPUT_FILE'" 58 - else 59 - "$COPY_COMMAND" < "$OUTPUT_FILE" 50 + $COMMAND "$REGION_SWITCH" & 60 51 fi 61 - exit 0 62 52 } 63 53 64 54 printversion() { ··· 151 141 verbose "Region switch: $REGION_SWITCH" 152 142 verbose "Action: $ACTION" 153 143 154 - out_dir="$(dirname "$OUTPUT_FILE")" 155 - out_base="$(basename "$OUTPUT_FILE")" 156 - 157 - while read -r _ _ f; do 158 - if [[ "$f" == "$out_base" ]]; then 159 - copy 160 - kill $BASHPID 161 - fi 162 - done < <(inotifywait -q -m -e create "$out_dir") & 163 - inotify_pid=$! 164 - 165 - trap 'kill $inotify_pid' SIGINT 166 - 167 - verbose "Started inotifywait with PID $inotify_pid" 168 - 169 144 case "$ACTION" in 170 145 a*) 171 146 active ··· 178 153 ;; 179 154 *) 180 155 err "Unknown capture mode '$ACTION'" 181 - kill $inotify_pid 182 156 exit 1 183 157 ;; 184 158 esac 185 - 186 - verbose 'Waiting for file creation to happen' 187 - wait $inotify_pid