Skip to content

Instantly share code, notes, and snippets.

@dimfeld
Created November 15, 2023 22:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dimfeld/97f7c0cbb4422ac7bf2aef30fc090738 to your computer and use it in GitHub Desktop.
Save dimfeld/97f7c0cbb4422ac7bf2aef30fc090738 to your computer and use it in GitHub Desktop.
Quickly create and switch between Kitty os windows by name
sw() {
if [[ -n "$1" ]]; then
SWITCH_WIN=$(kitten @ ls | jq ".[] | select(.wm_name == \"$1\") | .tabs | .[]| select(.is_active) | .windows |.[]| select(.is_active) | .id" | head -n1)
if [[ -n "$SWITCH_WIN" ]]; then
kitten @ focus-window -m "id:${SWITCH_WIN}"
else
kitten @ launch --type os-window \
--os-window-title "kitty: $1" \
--os-window-name "$1"
fi
return
fi
SWITCH_TO=$(kitten @ ls | jq -r '.[] | .wm_name' | fzf --exit-0)
if [ -z "$SWITCH_TO" ]; then
return
fi
# Get the ID of the window selected above
SWITCH_WIN=$(kitten @ ls | jq ".[] | select(.wm_name == \"${SWITCH_TO}\") | .tabs | .[]| select(.is_active) | .windows |.[]| select(.is_active) | .id" | head -n1)
kitten @ focus-window -m "id:${SWITCH_WIN}"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment