dotfiles/bin/t
Oliver Davies 624faf959c refactor: restructure my Code directory
I recently restructed the contents of my `~/Code` directory so that
repositories are grouped by their provider and organisation.

For example, my `dotfiles` are now located at
`~/Code/github.com/opdavies/dotfiles`.

Likewise, `build-configs` is now located at
`~/Code/github.com/OliverDaviesLtd/build-configs` as it's within the
`OliverDaviesLtd` organisation.

As well as `~/Code/github.com`, I also have `~/Code/bitbucket.org` for
Bitbucket repositories. These are also grouped within subdirectories for
each organisation.

This change means I need to update any reference to the old `dotfiles`
location to the new one and I can update the `t` function to adjust the
min and max depth it uses to find directories.
2023-08-07 09:53:33 +01:00

43 lines
1.1 KiB
Bash
Executable file

#!/usr/bin/env bash
# Quickly navigate between different directories using fzf and tmux sessions
# (Thanks, ThePrimeagen!).
#
# https://github.com/ThePrimeagen/.dotfiles/blob/master/bin/.local/bin/tmux-sessionizer
# https://frontendmasters.com/workshops/dev-productivity
if [[ $# -eq 1 ]]; then
selected=$1
else
# Get the session name from fuzzy-finding list of directories and generating a
# tmux-safe version.
items=$(find ~/Code -mindepth 3 -maxdepth 3 -type d ! -name .git)
items+="$HOME/Code/github.com/opdavies/dotfiles"
selected=$(echo "${items}" | sort | fzf --reverse)
fi
if [[ -z $selected ]]; then
exit 0
fi
is_tmux_running=$(pgrep tmux)
selected_name=$(basename "$selected" | tr . -)
if [[ -z $TMUX ]] && [[ -z $is_tmux_running ]]; then
tmux new-session -s $selected_name -c $selected
exit 0
fi
# Create a new session if tmux does not already have a session matching the
# selected session name.
if ! tmux has-session -t $selected_name 2> /dev/null; then
tmux new-session -s $selected_name -c $selected -d
fi
if [[ -z $TMUX ]]; then
tmux attach-session -t $selected_name
else
tmux switch-client -t $selected_name
fi