fix(tmuxinator): add first match completion
This commit is contained in:
@@ -1,28 +1,36 @@
|
||||
function mux() {
|
||||
project_dir=$1
|
||||
if [[ -z "$project_dir" ]]; then
|
||||
echo "Usage: mux <project_directory> [session_name]"
|
||||
function mx() {
|
||||
PROJECT_DIR=$1
|
||||
if [[ -z "$PROJECT_DIR" ]]; then
|
||||
echo "Usage: mux <project_directory> [SESSION_NAME]"
|
||||
return 1
|
||||
fi
|
||||
session_name=${2:-$(basename $(realpath "$project_dir"))}
|
||||
whole_path=$(realpath "$project_dir")
|
||||
if [[ $whole_path == "*No such file or directory*" ]]; then
|
||||
echo "Directory does not exist: $project_dir"
|
||||
|
||||
ALL_PROJECTS=$(tmuxinator list | grep -v tmuxinator)
|
||||
IS_VALID_PROJECT=$(echo $ALL_PROJECTS | grep -o "\b$PROJECT_DIR\w*" | head -1)
|
||||
if [[ $IS_VALID_PROJECT != "" ]]; then
|
||||
echo $IS_VALID_PROJECT
|
||||
tmuxinator start "$IS_VALID_PROJECT"
|
||||
return 1
|
||||
fi
|
||||
|
||||
SESSION_NAME=${2:-$(basename $(realpath "$PROJECT_DIR"))}
|
||||
WHOLE_PATH=$(realpath "$PROJECT_DIR")
|
||||
if [[ $WHOLE_PATH == "*No such file or directory*" ]]; then
|
||||
echo "Directory does not exist: $PROJECT_DIR"
|
||||
return 1
|
||||
fi
|
||||
|
||||
# check if file doesn't exist yet in the tmuxinator config directory
|
||||
tmuxinator_config=~/.config/tmuxinator/$session_name.yml
|
||||
if [[ -f $tmuxinator_config ]]; then
|
||||
echo "File already exists"
|
||||
TMUXINATOR_CONFIG=~/.config/tmuxinator/$SESSION_NAME.yml
|
||||
if [[ -f $TMUXINATOR_CONFIG ]]; then
|
||||
else
|
||||
cp ~/.config/tmuxinator/template.yml.temp $tmuxinator_config
|
||||
cp ~/.config/tmuxinator/template.yml.temp $TMUXINATOR_CONFIG
|
||||
# replace variables in placeholder config with real values - PROJECT_NAME, PROJECT_ROOT
|
||||
sed -i '' "s|{{\$PROJECT_NAME}}|$session_name|g" $tmuxinator_config
|
||||
sed -i '' "s|{{\$PROJECT_ROOT}}|$whole_path|g" "$tmuxinator_config"
|
||||
sed -i '' "s|{{\$PROJECT_NAME}}|$SESSION_NAME|g" $TMUXINATOR_CONFIG
|
||||
sed -i '' "s|{{\$PROJECT_ROOT}}|$WHOLE_PATH|g" "$TMUXINATOR_CONFIG"
|
||||
fi
|
||||
|
||||
tmuxinator start $session_name
|
||||
tmuxinator start $SESSION_NAME
|
||||
|
||||
}
|
||||
complete -o default mux
|
||||
|
||||
Reference in New Issue
Block a user