diff --git a/env/.config/utils-launcher/config.json b/env/.config/utils-launcher/config.json index 387ba5b..219999b 100644 --- a/env/.config/utils-launcher/config.json +++ b/env/.config/utils-launcher/config.json @@ -12,7 +12,7 @@ { "name": "Clipboard - clear history", "description": "Clear the clipboard history file.", - "exec": "$SCRIPTS/hypr/clear-clipboard-history && echo Done" + "exec": "$SCRIPTS/hypr/clear-clipboard-history --notify-complete" }, { "name": "Monitors - stats / picker", diff --git a/env/.local/scripts/hypr/clear-clipboard-history b/env/.local/scripts/hypr/clear-clipboard-history index 057bebf..a26b73b 100755 --- a/env/.local/scripts/hypr/clear-clipboard-history +++ b/env/.local/scripts/hypr/clear-clipboard-history @@ -1,8 +1,21 @@ #!/bin/bash -#wl-copy --clear >/dev/null 2>&1 && \ -if [ -n "$WAYLAND_DISPLAY" ]; then +notify_flag="0" +XDG_DATA_HOME=${XDG_DATA_HOME:-$HOME/.local/share} + +while [[ $# -gt 0 ]]; do + if [[ $1 == "-n" ]] || [[ $1 == "--notify-complete" ]]; then + notify_flag="1" + fi + shift +done + +if [[ -n "$WAYLAND_DISPLAY" ]]; then wl-copy --clear fi -rm ~/.local/share/clipse/clipboard_history.json >/dev/null 2>&1 +rm $XDG_DATA_HOME/clipse/clipboard_history.json >/dev/null 2>&1 + +if [[ $notify_flag == "1" ]] && [[ -n "$WAYLAND_DISPLAY" ]]; then + notify-send --urgency=low --expire-time=3000 --app-name="Clipboard History" "✅ Cleared clipboard history" +fi diff --git a/env/.local/scripts/hypr/window-picker b/env/.local/scripts/hypr/window-picker index 9f54b2a..5d7bbc5 100755 --- a/env/.local/scripts/hypr/window-picker +++ b/env/.local/scripts/hypr/window-picker @@ -76,9 +76,11 @@ sel=$( --preview-label='[ Window Stats ]' --delimiter='|' --with-nth=2 \ --preview="$SCRIPTS/hypr/preview-stats window {1}" ) +status=$? [[ -z $sel ]] && exit 1 # revove everything but the address portion. sel=${sel%%|*} echo "$sel" +exit $status diff --git a/env/.local/scripts/hypr/windowctl b/env/.local/scripts/hypr/windowctl index e0e7b9a..7e212f5 100755 --- a/env/.local/scripts/hypr/windowctl +++ b/env/.local/scripts/hypr/windowctl @@ -1,5 +1,4 @@ #!/usr/bin/env bash - THIS_FILE=${BASH_SOURCE[0]} THIS=$(basename $THIS_FILE) @@ -47,6 +46,8 @@ launch_flag="0" move_flag="0" move_silent_flag="0" move_to_workspace_name="" +refresh_flag="0" +should_quit="0" launch_args=() selected_value="" @@ -104,10 +105,26 @@ log() { logging log --source "$THIS_FILE" "$@" } +# Reset flags and selection. +reset_flags() { + selected_value="" + clipboard_flag="0" + close_flag="0" + focus_flag="0" + ignore_flag="0" + launch_flag="0" + move_flag="0" + move_silent_flag="0" + move_to_workspace_name="" + refresh_flag="0" + should_quit="0" +} + ask_what_to_do_with_selection() { local choices=( "Focus the selected window.:Focus window" "Close the selected window.:Close window" + "Close the selected window and go back to the window list.:Close window and back" "Move the selected window to another workspace, focusing the window.\n\nA workspace picker will be presented to choose which workspace to move to.:Move to workspace" "Move the selected window to another workspace, without focusing the window.\n\nA workspace picker will be presented to choose which workspace to move to.:Move to workspace - silent" "Copy the window address to the system clipboard:Copy to clipboard" @@ -120,27 +137,38 @@ ask_what_to_do_with_selection() { --delimiter=':' --with-nth=2 \ --header="What should we do with the selected window?" \ --preview-label="[ Description ]" \ - --preview='echo -e {1}' + --preview="echo -e {1}; echo -e '\n\n\e[35mSelected Window:\e[0m'; $SCRIPTS/hypr/preview-stats window $selected_value;" ) # Set choice to just the action portion. choice="${choice#*:}" log "Choice: $choice" + + # Set appropriate flags based on the choice. if [[ $choice == "Quit" ]]; then exit 0 elif [[ $choice == "Close window" ]]; then + should_quit="1" close_flag="1" + elif [[ $choice == "Close window and back" ]]; then + close_flag="1" + refresh_flag="1" + should_quit="0" elif [[ $choice == "Copy to clipboard" ]]; then + should_quit="1" clipboard_flag="1" elif [[ $choice == "Focus window" ]]; then + should_quit="1" focus_flag="1" elif [[ $choice == "Move to workspace" ]]; then + should_quit="1" move_flag="1" elif [[ $choice == "Move to workspace - silent" ]]; then + should_quit="1" move_silent_flag="1" move_flag="1" elif [[ $choice == "Refresh window list" ]]; then - eval exec ${BASH_SOURCE[0]} - exit 0 + refresh_flag="1" + should_quit="0" fi } @@ -207,20 +235,23 @@ handle_selected_value() { elif [[ $clipboard_flag == "1" ]]; then log "Copying to clipboard, selection: $selected_value" wl-copy $selected_value - exit 0 elif [[ $focus_flag == "1" ]]; then - # log "Focusing window, selection: $selected_value" - # hypr_dispatch focuswindow "address:$selected_value" - focus_window && exit 0 + focus_window elif [[ $close_flag == "1" ]]; then log "Closing window, selection: $selected_value" hypr_dispatch closewindow "address:$selected_value" - exit 0 + if [[ $refresh_flag == "1" ]]; then + log "Refreshing windows..." + # Need to sleep here breifly otherwise recently closed windows will still show + # in the window picker. + reset_flags && sleep 0.3 + fi elif [[ $move_flag == "1" ]] || [[ $move_silent_flag == "1" ]]; then - move_to_workspace && exit 0 + move_to_workspace + # && exit 0 + else + log "No flag set, selection: '$selected_value'" fi - # TODO: Choose from list of what to do with the selected_value. - log "No flag set, selection: '$selected_value'" } ################################################## @@ -244,19 +275,39 @@ else [[ -f $SCRIPTS/catppuccin-colors ]] && source $SCRIPTS/catppuccin-colors - if [[ -z $selected_value ]]; then - selected_value=$("$SCRIPTS/hypr/window-picker") - fi - if [[ -n $selected_value ]]; then - handle_selected_value - # If we got here then no flag was passed in initially on how to handle the - # selected window, so ask what they'd like to do. Then handle it. - log "Asking what to do with selction." - ask_what_to_do_with_selection + # Handle value if it was passed in. + # TODO: This should probably ensure that flags were set. + handle_selected_value && exit 0 + else - [[ -n $selected_value ]] && handle_selected_value - # If you make it here, We just give up... Don't start an endless loop. - log "Giving up without a selection." + trap 'log "Stoping..."; should_quit="1"' SIGINT + + while [[ $should_quit == "0" ]]; do + + # not sure if this should be here or somewhere else, as it will + # cause any passed in flags to be ignored, but they're generally empty + # when using this interactive mode anyway. + reset_flags + + selected_value=$("$SCRIPTS/hypr/window-picker") + status=$? + + if [[ $status -ne 0 ]]; then + should_quit="1" + else + if [[ -n $selected_value ]]; then + handle_selected_value + # If we got here then no flag was passed in initially on how to handle the + # selected window, so ask what they'd like to do. Then handle it. + log "Asking what to do with selction." + ask_what_to_do_with_selection + + [[ -n $selected_value ]] && handle_selected_value + # If you make it here, We just give up... Don't start an endless loop. + # log "Giving up without a selection." + fi + fi + done fi fi