diff --git a/bin/.bin/dmenu/actOnLast b/bin/.bin/dmenu/actOnLast new file mode 100755 index 00000000..9664e942 --- /dev/null +++ b/bin/.bin/dmenu/actOnLast @@ -0,0 +1,110 @@ +#!/usr/bin/env bash + +# This file should be bound to a keybinging +# It allows for follow up actions +# +# For example, after taking a screenshot, I may wish to +# * add a shadow +# * open in gimp +# * Apply tesseract ocr + +# The file .local/share/lastaction will contain the last action and potentially relevant information about it such as the screenshot's path + + +# If this is true, the first is automatically taken +first=false + +die(){ + echo "$@" > /dev/stderr + exit 1 +} + +trimWhitespace(){ + sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//' +} + +deleteEmptyLines(){ + sed '/^$/ d' +} + +getSuggestions(){ + case "$1" in + screenshot) + printf "View\tsxiv\n" + printf "add shadow\tscreenshotAddShadow\n" + printf "OCR\tscreenshotOCR\n" + ;; + password) + echo "OTP passwordOTP" + ;; + esac + +} + +screenshotOCR(){ + file="$1" + tesseract "$file" "$file" + LINES=$(wc -l < "${file}.txt") + if [ "$LINES" -eq 0 ]; then + notify-send "ocr" "no text was detected\nimage file at $file" + exit 1 + fi + if [ -n "$WAYLAND_DISPLAY" ]; then + cat "${file}.txt" | wl-copy + echo -n "${file}.txt" | wl-copy --primary + else + cat "${file}.txt" | xclip -selection clipboard + echo -n "${file}.txt" | xclip -selection primary + fi +} + +screenshotAddShadow(){ + file="$1" + newfile="${file%.*}-withshadow.${file##*.}" + [ ! -f "$file" ] && die "Can't find file" + + #tmpfile="$(mktemp)" + convert "$file" \( +clone -background black -shadow 80x20+0+15 \) +swap -background transparent -layers merge +repage "$newfile" + #convert "$tmpfile" -bordercolor none -border 32 "$newfile" + #rm "$tmpfile" + if [ -n "$WAYLAND_DISPLAY" ]; then + # Copies the image to your clipboard (ctrl + v) + wl-copy < "$file" + # Copies the filename to primary selection (shift + insert or middle mouse) + echo -n "$file" | wl-copy --primary + else + # Copies the image to your clipboard (ctrl + v) + xclip -selection clipboard -target image/png -i "$newfile" + # Copies the filename to primary selection (shift + insert or middle mouse) + echo -n "$newfile" | xclip -selection primary + fi + notify-send "New Shadow On Screenshot" "$newfile" + echo "screenshot $newfile" > "$lastactionfile" +} + +passwordOTP(){ + password-manager "$1" otp +} + +[ "$1" == "--first" ] && first=true && shift +lastactionfile="${XDG_DATA_HOME:-$HOME/.local/share}/lastaction" +[ ! -f "$lastactionfile" ] && die "No last action" + +lastaction="$(sed -n 1p "$lastactionfile")" +[ -z "$lastaction" ] && die "No last action" + +action="$(echo "$lastaction" | cut -d ' ' -f 1)" +options="$(echo "$lastaction" | cut -d ' ' -f 2-)" + +suggestions="$(getSuggestions "$action")" + +torun="" +if [ "$(echo "$suggestions" | wc -l)" -le 1 ] || [ "$first" == "true" ]; then + torun="$(echo "$suggestions" | sed -n 1p | cut -d ' ' -f 2)" +else + choice="$(echo "$suggestions" | cut -d ' ' -f 1 | rofi -dmenu)" + [ -z "$choice" ] && die "Exited without selection" + torun="$(echo "$suggestions" | grep "^$choice" | cut -d ' ' -f 2)" +fi + +$torun $options diff --git a/bin/.bin/dmenu/password-manager b/bin/.bin/dmenu/password-manager index 6b473cd2..bf79f00d 100755 --- a/bin/.bin/dmenu/password-manager +++ b/bin/.bin/dmenu/password-manager @@ -56,6 +56,7 @@ function copy_password(){ exit 1 fi echo "$pw" | clipboard + echo "password $password" > ~/.local/share/lastaction notify-send -t 3000 "Password put on clipboard" "Will be removed in 3 seconds" ( ( exec -a "$sleep_argv0" bash <<<"trap 'kill %1' TERM; sleep '3' & wait" ) @@ -84,7 +85,7 @@ if [ -d "$PASSWORDS" ]; then name="$(rofi -dmenu -p Name -lines 0)" # Todo - create new passwords else - if [ "$ret" -ne "11" ]; then + if [ "$ret" != "11" ]; then copy_password "$selection" "$ret" else type_password "$selection" "$ret" diff --git a/bin/.bin/screenshot b/bin/.bin/screenshot index d9e553b8..b32cfeba 100755 --- a/bin/.bin/screenshot +++ b/bin/.bin/screenshot @@ -11,9 +11,11 @@ # Relies on maim for taking screenshot # If you give it the -o flag for ocr, it needs tesseract + path='/tmp' command -v maim > /dev/null && screenshooter="maim" || ( echo -n "You need to install maim\nhttps://github.com/naelstrof/maim" && exit 1 ) ocr="false" +lastactionfile="${XDG_DATA_HOME:-$HOME/.local/share}/lastaction" #If a project is set we will put screenshots in the project's folder command -v project > /dev/null && project=$(project current --path) @@ -29,7 +31,7 @@ file="${path}/${filename}" [ "$1" = "-w" ] && sleep "$2" && shift && shift [ "$1" = "-o" ] && ocr="true" && shift -case $1 in +case "$1" in "window") if [ -n "$WAYLAND_DISPLAY" ]; then notify-send "Can't get current window yet in wayland" @@ -54,36 +56,21 @@ case $1 in ;; esac -if [ -f "$file" ]; then - if [ "$ocr" == "true" ]; then - # Input and output files look the same because tesseract adds .txt to whatever we give as the output file - tesseract "$file" "$file" - LINES=$(wc -l < "${file}.txt") - if [ "$LINES" -eq 0 ]; then - notify-send "ocr" "no text was detected\nimage file at $file" - exit 1 - fi - if [ -n "$WAYLAND_DISPLAY" ]; then - cat "${file}.txt" | wl-copy - echo -n "${file}.txt" | wl-copy --primary - else - cat "${file}.txt" | xclip -selection clipboard - echo -n "${file}.txt" | xclip -selection primary - fi + +if [ -f "$file" ]; then + if [ -n "$WAYLAND_DISPLAY" ]; then + # Copies the image to your clipboard (ctrl + v) + wl-copy < "$file" + # Copies the filename to primary selection (shift + insert or middle mouse) + echo -n "$file" | wl-copy --primary else - if [ -n "$WAYLAND_DISPLAY" ]; then - # Copies the image to your clipboard (ctrl + v) - wl-copy < "$file" - # Copies the filename to primary selection (shift + insert or middle mouse) - echo -n "$file" | wl-copy --primary - else - # Copies the image to your clipboard (ctrl + v) - xclip -selection clipboard -target image/png -i "$file" - # Copies the filename to primary selection (shift + insert or middle mouse) - echo -n "$file" | xclip -selection primary - fi - # Creates notification with file name - notify-send "New Screenshot" "$file" + # Copies the image to your clipboard (ctrl + v) + xclip -selection clipboard -target image/png -i "$file" + # Copies the filename to primary selection (shift + insert or middle mouse) + echo -n "$file" | xclip -selection primary fi + # Creates notification with file name + notify-send "New Screenshot" "$file" + echo "screenshot $file" > "$lastactionfile" fi