#!/usr/bin/env bash THIS_FILE=${BASH_SOURCE[0]} THIS=$(basename $THIS_FILE) usage() { cat </dev/null 2>&1 return $? } move_to_workspace() { local workspace_id="" if [[ -z $move_to_workspace_name ]]; then move_to_workspace_name=$( $SCRIPTS/hypr/workspace-picker --return-name-if-special \ --header="Select a workspace to move window to:" ) fi if [[ -z $move_to_workspace_name ]]; then log --error "No workspace set to move window to." exit 1 fi # Check if moving to a special workspace to pass the appropriate args in to hyprctl. if [[ $move_to_workspace_name =~ ^special ]]; then workspace_id=$move_to_workspace_name else workspace_id=$(hyprctl workspaces -j | jq -r ".[] | select(.name | contains(\"$move_to_workspace_name\")) | .id") fi if [[ -z $workspace_id ]]; then log --error "No workspace id found for: '$move_to_workspace_name'" exit 1 fi action="movetoworkspace" if [[ $move_silent_flag == "1" ]]; then action="movetoworkspacesilent" fi log "Moving window: '$selected_value' to workspace: '$workspace_id'" hypr_dispatch $action "$workspace_id,address:$selected_value" } handle_selected_value() { if [[ $ignore_flag == "1" ]]; then log "Ignore flag set, selection: '$selected_value'" exit 0 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" exit 0 elif [[ $close_flag == "1" ]]; then log "Closing window, selection: $selected_value" hypr_dispatch closewindow "address:$selected_value" exit 0 elif [[ $move_flag == "1" ]] || [[ $move_silent_flag == "1" ]]; then move_to_workspace && exit 0 fi # TODO: Choose from list of what to do with the selected_value. log "No flag set, selection: '$selected_value'" } ################################################## # MAIN ################################################## # Setup logging file and label. source "$SCRIPTS/hypr/logging" setup-logging "/tmp/$THIS.log" "$THIS" if [[ $launch_flag == "1" ]]; then ghostty --class="$window_class" --window-padding-x="$window_padding_x" \ --keybind="ctrl+c=quit" \ -e "${BASH_SOURCE[0]}" "${launch_args[@]}" else # Load colors if they haven't been loaded already. [[ -z ${FZF_DEFAULT_OPTS} ]] && [[ -f $SCRIPTS/catppuccin-colors ]] && source $SCRIPTS/catppuccin-colors selected_value=$("$SCRIPTS/hypr/window-picker") 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