refactor(tmux): sessionizer script
This commit is contained in:
parent
335db8d4bd
commit
0f3306c1d3
3 changed files with 68 additions and 94 deletions
|
@ -59,7 +59,7 @@ bind -r "<" swap-window -d -t -1
|
||||||
bind -r ">" swap-window -d -t +1
|
bind -r ">" swap-window -d -t +1
|
||||||
|
|
||||||
# Projects
|
# Projects
|
||||||
bind-key Enter popup -E -h 90% -w 100% -x C -y C "tf"
|
bind-key Space popup -E -h 85% -w 100% -x C -y C "tmux-sessionizer"
|
||||||
|
|
||||||
# Switch from Notes/Tasks Session with last session
|
# Switch from Notes/Tasks Session with last session
|
||||||
bind-key n run "tmux-session-switcher notes-tasks"
|
bind-key n run "tmux-session-switcher notes-tasks"
|
||||||
|
@ -67,3 +67,6 @@ bind-key m run "tmux-session-switcher mail"
|
||||||
|
|
||||||
# Switch to last used panel and zoom
|
# Switch to last used panel and zoom
|
||||||
bind-key Z select-pane -l \; resize-pane -Z
|
bind-key Z select-pane -l \; resize-pane -Z
|
||||||
|
|
||||||
|
# Toggle Bar
|
||||||
|
bind-key t set -g status
|
||||||
|
|
|
@ -1,93 +0,0 @@
|
||||||
#!/bin/bash
|
|
||||||
|
|
||||||
# Constants
|
|
||||||
gfetch="gfetch -d churn contributors --no-color-palette --no-title"
|
|
||||||
ls="eza --header --icons --all --color=always --group-directories-first --hyperlink"
|
|
||||||
projects_dir="$HOME/dev"
|
|
||||||
projects_command="find $projects_dir -mindepth 2 -maxdepth 2 -type d"
|
|
||||||
fzf_command="fzf -i --height=100% --preview-window=65%"
|
|
||||||
zoxide_command="zoxide query -l"
|
|
||||||
|
|
||||||
yaml_config() {
|
|
||||||
local yaml_file="$1"
|
|
||||||
local dest_dir="$2"
|
|
||||||
local dest_yaml_file="$dest_dir/.tmuxp.yaml"
|
|
||||||
|
|
||||||
cp "$yaml_file" "$dest_yaml_file"
|
|
||||||
sed -i "1i start_directory: $dest_dir\nsession_name: $tab_title" "$dest_yaml_file"
|
|
||||||
}
|
|
||||||
|
|
||||||
tmuxp_load() {
|
|
||||||
launch_docs
|
|
||||||
if [[ -n "$TMUX" ]]; then
|
|
||||||
tmuxp load -y "$selected_dir"
|
|
||||||
zoxide_score
|
|
||||||
else
|
|
||||||
tmuxp load "$selected_dir"
|
|
||||||
zoxide_score
|
|
||||||
fi
|
|
||||||
|
|
||||||
# tmux switch-client -t "$tab_title"
|
|
||||||
}
|
|
||||||
|
|
||||||
handle_tmuxp() {
|
|
||||||
if [[ -f "$selected_dir/.tmuxp.yaml" ]]; then
|
|
||||||
tmuxp_load
|
|
||||||
else
|
|
||||||
if [[ -d "$XDG_CONFIG_HOME/tmuxp" ]]; then
|
|
||||||
local yaml_file=$(find "$XDG_CONFIG_HOME/tmuxp" -name "*.yaml" -print0 |
|
|
||||||
xargs -0 -n 1 basename | sed 's/\.yaml$//' |
|
|
||||||
fzf --preview "bat --style=numbers --color=always $XDG_CONFIG_HOME/tmuxp/{}.yaml" \
|
|
||||||
--prompt="Select a session file: ")
|
|
||||||
if [[ -n "$yaml_file" ]]; then
|
|
||||||
yaml_config "$XDG_CONFIG_HOME/tmuxp/$yaml_file.yaml" "$selected_dir"
|
|
||||||
tmuxp_load
|
|
||||||
else
|
|
||||||
handle_tmux
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
handle_tmux() {
|
|
||||||
if [[ -n "$TMUX" ]]; then
|
|
||||||
tmux new-session -ds "$tab_title" -c "$selected_dir"
|
|
||||||
tmux switch-client -t "$tab_title"
|
|
||||||
else
|
|
||||||
tmux new-session -s "$tab_title" -c "$selected_dir"
|
|
||||||
fi
|
|
||||||
zoxide_score
|
|
||||||
}
|
|
||||||
|
|
||||||
zoxide_score() {
|
|
||||||
if command -v zoxide &>/dev/null; then
|
|
||||||
zoxide add "$selected_dir"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
launch_docs() {
|
|
||||||
if ! tmux has-session -t "$SESSION_NOTES" 2>/dev/null; then
|
|
||||||
tmuxp load -d notes-tasks
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
selected_dir=$(
|
|
||||||
$projects_command | $fzf_command \
|
|
||||||
--prompt='Select a directory: ' \
|
|
||||||
--bind "ctrl-r:reload($projects_command)+change-preview($gfetch {} && $ls {})" \
|
|
||||||
--bind "ctrl-z:reload($zoxide_command)+change-preview($ls {})" \
|
|
||||||
--header "ctrl-r: repos | ctrl-z: zoxide" \
|
|
||||||
--preview "$gfetch {} && $ls {}"
|
|
||||||
)
|
|
||||||
|
|
||||||
tab_title=$(basename "$selected_dir")
|
|
||||||
|
|
||||||
if [[ -n "$selected_dir" ]]; then
|
|
||||||
if command -v tmux &>/dev/null; then
|
|
||||||
if command -v tmuxp &>/dev/null; then
|
|
||||||
handle_tmuxp
|
|
||||||
else
|
|
||||||
handle_tmux
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
fi
|
|
64
.local/bin/tmux-sessionizer
Executable file
64
.local/bin/tmux-sessionizer
Executable file
|
@ -0,0 +1,64 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Constants
|
||||||
|
gfetch="onefetch -d churn contributors --no-color-palette --no-title"
|
||||||
|
ls="eza --header --icons --all --color=always --group-directories-first --hyperlink"
|
||||||
|
projects_dir="$HOME/dev"
|
||||||
|
projects_command="fd --exact-depth 2 --type=directory . $projects_dir"
|
||||||
|
config_command="fd --exact-depth 1 --type=directory . $HOME/.config"
|
||||||
|
fzf_command="fzf -i --height=100% --preview-window=70% --with-nth -2,-1 -d /"
|
||||||
|
zoxide_command="zoxide query -l"
|
||||||
|
|
||||||
|
tmuxp_load() {
|
||||||
|
if [[ -n "$TMUX" ]]; then
|
||||||
|
tmuxp load -y "$selected_dir" --log-file "$XDG_DATA_HOME"/tmux/tmuxp.log
|
||||||
|
zoxide_score
|
||||||
|
else
|
||||||
|
tmuxp load "$selected_dir" --log-file "$XDG_DATA_HOME"/tmux/tmuxp.log
|
||||||
|
zoxide_score
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
handle_tmuxp() {
|
||||||
|
if [[ -f "$selected_dir/.tmuxp.yaml" ]]; then
|
||||||
|
tmuxp_load
|
||||||
|
else
|
||||||
|
handle_tmux
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
handle_tmux() {
|
||||||
|
if [[ -n "$TMUX" ]]; then
|
||||||
|
tmux new-session -ds "$tab_title" -c "$selected_dir"
|
||||||
|
tmux switch-client -t "$tab_title"
|
||||||
|
else
|
||||||
|
tmux new-session -s "$tab_title" -c "$selected_dir"
|
||||||
|
fi
|
||||||
|
zoxide_score
|
||||||
|
}
|
||||||
|
|
||||||
|
zoxide_score() {
|
||||||
|
if command -v zoxide &>/dev/null; then
|
||||||
|
zoxide add "$selected_dir"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
selected_dir=$(
|
||||||
|
$projects_command | $fzf_command \
|
||||||
|
--prompt='Select a directory: ' \
|
||||||
|
--bind "ctrl-p:reload($projects_command)+change-preview($gfetch {} && $ls {})" \
|
||||||
|
--bind "ctrl-o:reload($config_command)+change-preview($ls {})" \
|
||||||
|
--bind "ctrl-z:reload($zoxide_command)+change-preview($ls {})" \
|
||||||
|
--header "ctrl-p: projects | ctrl-o: config | ctrl-z: zoxide" \
|
||||||
|
--preview "$gfetch {} && $ls {}"
|
||||||
|
)
|
||||||
|
|
||||||
|
tab_title=$(basename "$selected_dir")
|
||||||
|
|
||||||
|
if [[ -n "$selected_dir" ]]; then
|
||||||
|
if command -v tmuxp &>/dev/null; then
|
||||||
|
handle_tmuxp
|
||||||
|
else
|
||||||
|
handle_tmux
|
||||||
|
fi
|
||||||
|
fi
|
Loading…
Add table
Reference in a new issue