From cb8f07a711bc6bcb44ae611a288cdeb08ae2f801 Mon Sep 17 00:00:00 2001 From: david Date: Wed, 15 Jan 2025 00:44:24 -0600 Subject: [PATCH] Move copy targets into directory; add tmux sessionizer --- copy_configs | 6 +-- pre_run_01 | 21 +++++--- {.config => src_files/.config}/nvim/init.lua | 0 {.config => src_files/.config}/tmux/tmux.conf | 6 ++- .../.config}/zsh/.zshrc-job-rs | 0 .../.config}/zsh/.zshrc-life-system | 0 .../.local/bin/.tmux-session-setup-default | 10 ++++ src_files/.local/bin/tmux-sessionizer | 49 +++++++++++++++++++ .../.local}/scripts/zxcv-placeholder | 0 .zshrc => src_files/.zshrc | 2 +- 10 files changed, 81 insertions(+), 13 deletions(-) rename {.config => src_files/.config}/nvim/init.lua (100%) rename {.config => src_files/.config}/tmux/tmux.conf (85%) rename {.config => src_files/.config}/zsh/.zshrc-job-rs (100%) rename {.config => src_files/.config}/zsh/.zshrc-life-system (100%) create mode 100644 src_files/.local/bin/.tmux-session-setup-default create mode 100644 src_files/.local/bin/tmux-sessionizer rename {.local => src_files/.local}/scripts/zxcv-placeholder (100%) rename .zshrc => src_files/.zshrc (100%) diff --git a/copy_configs b/copy_configs index a17e21f..d75ad3d 100755 --- a/copy_configs +++ b/copy_configs @@ -38,6 +38,6 @@ copy_file() { execute cp -p $from $to/$filename } -copy_dir .config $HOME/.config -copy_dir .local $HOME/.local -copy_file .zshrc $HOME +copy_dir src_files/.config $HOME/.config +copy_dir src_files/.local $HOME/.local +copy_file src_files/.zshrc $HOME diff --git a/pre_run_01 b/pre_run_01 index e1df342..b317648 100755 --- a/pre_run_01 +++ b/pre_run_01 @@ -1,10 +1,17 @@ #!/bin/zsh -[[ ! -d $HOME/.config ]] && mkdir $HOME/.config -[[ ! -d $HOME/.local ]] && mkdir $HOME/.local -[[ ! -d $HOME/.local/bin ]] && mkdir $HOME/.local/bin -[[ ! -d $HOME/.local/build ]] && mkdir $HOME/.local/build -[[ ! -d $HOME/.local/tmp ]] && mkdir $HOME/.local/tmp +mkdirs_before_copying_config_files() { + [[ ! -d $HOME/.config ]] && mkdir $HOME/.config + [[ ! -d $HOME/.local ]] && mkdir $HOME/.local + [[ ! -d $HOME/.local/bin ]] && mkdir $HOME/.local/bin + [[ ! -d $HOME/.local/build ]] && mkdir $HOME/.local/build + [[ ! -d $HOME/.local/tmp ]] && mkdir $HOME/.local/tmp +} -# [[ ! -d $HOME/dbox ]] && mkdir $HOME/dbox -[[ ! -d $HOME/dev ]] && mkdir $HOME/dev +mkdirs_after_setting_shell_env_vars() { + [[ ! -d $HOMEBOX ]] && mkdir $HOMEBOX + [[ ! -d $DEVDIR ]] && mkdir $DEVDIR +} + +mkdirs_before_copying_config_files +mkdirs_after_setting_shell_env_vars diff --git a/.config/nvim/init.lua b/src_files/.config/nvim/init.lua similarity index 100% rename from .config/nvim/init.lua rename to src_files/.config/nvim/init.lua diff --git a/.config/tmux/tmux.conf b/src_files/.config/tmux/tmux.conf similarity index 85% rename from .config/tmux/tmux.conf rename to src_files/.config/tmux/tmux.conf index 8cca54a..63cad33 100644 --- a/.config/tmux/tmux.conf +++ b/src_files/.config/tmux/tmux.conf @@ -17,9 +17,11 @@ bind -r j select-pane -D bind -r h select-pane -L bind -r l select-pane -R +# reload tmux.conf bind r source-file "~/.config/tmux/tmux.conf" \; display-message "tmux.conf reloaded" +# use tmux-sessionizer in place of f find +bind-key -r f run-shell "tmux neww ~/.local/bin/tmux-sessionizer" + # bind -r D neww -c "#{pane_current_path}" "[[ -e TODO.md ]] && nvim TODO.md || nvim ~/personal/dev/todo.md" -# bind-key -r f run-shell "tmux neww ~/.local/bin/tmux-sessionizer" - diff --git a/.config/zsh/.zshrc-job-rs b/src_files/.config/zsh/.zshrc-job-rs similarity index 100% rename from .config/zsh/.zshrc-job-rs rename to src_files/.config/zsh/.zshrc-job-rs diff --git a/.config/zsh/.zshrc-life-system b/src_files/.config/zsh/.zshrc-life-system similarity index 100% rename from .config/zsh/.zshrc-life-system rename to src_files/.config/zsh/.zshrc-life-system diff --git a/src_files/.local/bin/.tmux-session-setup-default b/src_files/.local/bin/.tmux-session-setup-default new file mode 100644 index 0000000..4904a74 --- /dev/null +++ b/src_files/.local/bin/.tmux-session-setup-default @@ -0,0 +1,10 @@ +#!/bin/zsh + +if [[ "$(pwd)" == $HOME || "$(pwd)" == $HOMEBOX ]]; then + clear + return +fi +tmux new-window -dn scratch +vim . +clear + diff --git a/src_files/.local/bin/tmux-sessionizer b/src_files/.local/bin/tmux-sessionizer new file mode 100644 index 0000000..2470c03 --- /dev/null +++ b/src_files/.local/bin/tmux-sessionizer @@ -0,0 +1,49 @@ +#!/bin/zsh + +switch_to() { + if [[ -z $TMUX ]]; then + tmux attach-session -t $1 + else + tmux switch-client -t $1 + fi +} + +has_session() { + tmux list-sessions | grep -q "^$1:" +} + +hydrate() { + if [ -f $2/.tmux-sessionizer ]; then + tmux send-keys -t $1 "source $2/.tmux-session-setup" c-M + elif [ -f $HOME/.tmux-sessionizer ]; then + tmux send-keys -t $1 "source $HOME/.tmux-session-setup" c-M + fi +} + +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) +fi + +if [[ -z $selected ]]; then + exit 0 +fi + +selected_name=$(basename "$selected" | tr . _) +tmux_running=$(pgrep tmux) + +if [[ -z $TMUX ]] && [[ -z $tmux_running ]]; then + tmux new-session -s $selected_name -c $selected + hydrate $selected_name $selected + exit 0 +fi + +if ! has_session $selected_name; then + tmux new-session -ds $selected_name -c $selected + hydrate $selected_name $selected +fi + +switch_to $selected_name diff --git a/.local/scripts/zxcv-placeholder b/src_files/.local/scripts/zxcv-placeholder similarity index 100% rename from .local/scripts/zxcv-placeholder rename to src_files/.local/scripts/zxcv-placeholder diff --git a/.zshrc b/src_files/.zshrc similarity index 100% rename from .zshrc rename to src_files/.zshrc index 433777e..27ca8e0 100644 --- a/.zshrc +++ b/src_files/.zshrc @@ -11,12 +11,12 @@ export PATH=$HOME/.local/bin:$HOME/.local/scripts:$PATH export PATH=$PATH:/opt/homebrew/opt/ccache/libexec # executable name overrides +alias ls='ls -F' alias vim='nvim' # shortcuts for common commands alias 3e='echo;echo;echo' alias 12e='3e;3e;3e;3e' -alias ls='ls -F' alias cl='clear; ' alias cls='clear;ls'