From 7beed41ab87d1275efcca67313c48eefc964a44c Mon Sep 17 00:00:00 2001 From: Bastian Asmussen Date: Tue, 12 Nov 2024 21:50:39 +0100 Subject: [PATCH 1/2] feat: add dynamic search paths for tmux-sessionizer Added dynamic search paths through the TMUX_SESSIONIZER_PATHS environment variable --- README.md | 7 +++++-- tmux-sessionizer | 6 +++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index ee449b9..0d667cc 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,10 @@ its a script that does everything awesome at all times tmux-sessionizer [] ``` +### Changing search paths +```bash +export TMUX_SESSIONIZER_PATHS="~/projects ~/work" +``` + if you execute tmux-sessionizer without any parameters it will assume FZF and try to fuzzy find over a set of directories. - -TODO: waiting on that directory list to be dynamic :) (go a head make pr if you want) diff --git a/tmux-sessionizer b/tmux-sessionizer index fa1bec5..93bae4c 100755 --- a/tmux-sessionizer +++ b/tmux-sessionizer @@ -22,9 +22,9 @@ hydrate() { if [[ $# -eq 1 ]]; then selected=$1 else - # If someone wants to make this extensible, i'll accept - # PR - selected=$(find ~/ ~/personal ~/personal/dev/env/.config -mindepth 1 -maxdepth 1 -type d | fzf) + # Use TMUX_SESSIONIZER_PATHS if set, otherwise default paths. + paths=${TMUX_SESSIONIZER_PATHS:-"~/ ~/personal ~/personal/dev/env/.config"} + selected=$(find $paths -mindepth 1 -maxdepth 1 -type d | fzf) fi if [[ -z $selected ]]; then From c0777f69faed032fa7351a881e86ed37ac4d6b37 Mon Sep 17 00:00:00 2001 From: Bastian Asmussen Date: Tue, 12 Nov 2024 23:38:45 +0100 Subject: [PATCH 2/2] fix: fixed path expansion issues --- tmux-sessionizer | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/tmux-sessionizer b/tmux-sessionizer index 93bae4c..59917ad 100755 --- a/tmux-sessionizer +++ b/tmux-sessionizer @@ -19,12 +19,22 @@ hydrate() { fi } +expand_paths() { + local paths="$1" expanded="" + for path in $paths; do + # Expand ~ to $HOME before passing to `realpath`. + expanded="$expanded $(realpath -m "${path/#\~/$HOME}" 2>/dev/null)" + done + + echo "$expanded" +} + if [[ $# -eq 1 ]]; then selected=$1 else # Use TMUX_SESSIONIZER_PATHS if set, otherwise default paths. - paths=${TMUX_SESSIONIZER_PATHS:-"~/ ~/personal ~/personal/dev/env/.config"} - selected=$(find $paths -mindepth 1 -maxdepth 1 -type d | fzf) + paths=$(expand_paths "${TMUX_SESSIONIZER_PATHS:-"~/ ~/personal ~/personal/dev/env/.config"}") + selected=$(find $paths -mindepth 1 -maxdepth 1 -type d 2>/dev/null | fzf) fi if [[ -z $selected ]]; then