Finish initial setup of tmux-sessionizer
This commit is contained in:
parent
cb8f07a711
commit
201cd90ee8
6
README.md
Normal file
6
README.md
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
### script run plan
|
||||||
|
- run `./pre_run*` scripts
|
||||||
|
- run `./run` to install/build/etc programs
|
||||||
|
- run `./copy_configs` to copy configs/scripts/executables into place
|
||||||
|
- run `./post_config*` scripts
|
||||||
|
|
14
copy_configs
14
copy_configs
@ -1,6 +1,6 @@
|
|||||||
#!/bin/zsh
|
#!/bin/zsh
|
||||||
|
|
||||||
dry="0"
|
local dry="0"
|
||||||
|
|
||||||
execute() {
|
execute() {
|
||||||
log "execute $@"
|
log "execute $@"
|
||||||
@ -19,10 +19,10 @@ done
|
|||||||
log "---------------- dotfiles ----------------"
|
log "---------------- dotfiles ----------------"
|
||||||
|
|
||||||
copy_dir() {
|
copy_dir() {
|
||||||
from=$1
|
local from=$1
|
||||||
to=$2
|
local to=$2
|
||||||
pushd $from > /dev/null
|
pushd $from > /dev/null
|
||||||
dirs=(`find . -mindepth 1 -maxdepth 1 -type d`)
|
local dirs=(`find . -mindepth 1 -maxdepth 1 -type d`)
|
||||||
for dir in $dirs; do
|
for dir in $dirs; do
|
||||||
[[ -d $to/$dir ]] && execute rm -rf $to/$dir
|
[[ -d $to/$dir ]] && execute rm -rf $to/$dir
|
||||||
execute cp -rp $dir $to/$dir
|
execute cp -rp $dir $to/$dir
|
||||||
@ -31,9 +31,9 @@ copy_dir() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
copy_file() {
|
copy_file() {
|
||||||
from=$1
|
local from=$1
|
||||||
to=$2
|
local to=$2
|
||||||
filename=$(basename $from)
|
local filename=$(basename $from)
|
||||||
[[ -e $to/$filename ]] && execute rm $to/$filename
|
[[ -e $to/$filename ]] && execute rm $to/$filename
|
||||||
execute cp -p $from $to/$filename
|
execute cp -p $from $to/$filename
|
||||||
}
|
}
|
||||||
|
8
post_config_01
Executable file
8
post_config_01
Executable file
@ -0,0 +1,8 @@
|
|||||||
|
#!/bin/zsh
|
||||||
|
|
||||||
|
mkdirs_after_setting_shell_env_vars() {
|
||||||
|
[[ ! -d $HOMEBOX ]] && mkdir $HOMEBOX
|
||||||
|
[[ ! -d $DEVDIR ]] && mkdir $DEVDIR
|
||||||
|
}
|
||||||
|
|
||||||
|
mkdirs_after_setting_shell_env_vars
|
@ -8,10 +8,4 @@ mkdirs_before_copying_config_files() {
|
|||||||
[[ ! -d $HOME/.local/tmp ]] && mkdir $HOME/.local/tmp
|
[[ ! -d $HOME/.local/tmp ]] && mkdir $HOME/.local/tmp
|
||||||
}
|
}
|
||||||
|
|
||||||
mkdirs_after_setting_shell_env_vars() {
|
|
||||||
[[ ! -d $HOMEBOX ]] && mkdir $HOMEBOX
|
|
||||||
[[ ! -d $DEVDIR ]] && mkdir $DEVDIR
|
|
||||||
}
|
|
||||||
|
|
||||||
mkdirs_before_copying_config_files
|
mkdirs_before_copying_config_files
|
||||||
mkdirs_after_setting_shell_env_vars
|
|
||||||
|
8
run
8
run
@ -1,7 +1,7 @@
|
|||||||
#!/bin/zsh
|
#!/bin/zsh
|
||||||
|
|
||||||
single_script_filter=""
|
local single_script_filter=""
|
||||||
dry="0"
|
local dry="0"
|
||||||
|
|
||||||
execute() {
|
execute() {
|
||||||
log "execute $@"
|
log "execute $@"
|
||||||
@ -17,10 +17,10 @@ while [[ $# > 0 ]]; do
|
|||||||
shift
|
shift
|
||||||
done
|
done
|
||||||
|
|
||||||
script_dir=$(cd $(dirname "${ZSH_SOURCE[0]}") &> /dev/null && pwd)
|
local script_dir=$(cd $(dirname "${ZSH_SOURCE[0]}") &> /dev/null && pwd)
|
||||||
log "run // script_dir: $script_dir -- args: $single_script_filter"
|
log "run // script_dir: $script_dir -- args: $single_script_filter"
|
||||||
cd $script_dir
|
cd $script_dir
|
||||||
scripts=(`find ./runs -maxdepth 1 -mindepth 1 -type f`)
|
local scripts=(`find ./runs -maxdepth 1 -mindepth 1 -type f`)
|
||||||
for script in $scripts; do
|
for script in $scripts; do
|
||||||
if [[ -x $script ]]; then
|
if [[ -x $script ]]; then
|
||||||
if echo "$script" | grep -qv "$single_script_filter"; then
|
if echo "$script" | grep -qv "$single_script_filter"; then
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
#!/bin/zsh
|
#!/bin/zsh
|
||||||
|
|
||||||
install_command="sudo apt install"
|
local install_command="sudo apt install"
|
||||||
[[ -x $(which brew) ]] && install_command="brew install"
|
[[ -x $(which brew) ]] && install_command="brew install"
|
||||||
|
|
||||||
neovim_dir=$HOME/.local/build/neovim
|
local neovim_dir=$HOME/.local/build/neovim
|
||||||
neovim_version="v0.10.3"
|
local neovim_version="v0.10.3"
|
||||||
[ ! -z $NVIM_VERSION ] && neovim_version="$NVIM_VERSION"
|
[ ! -z $NVIM_VERSION ] && neovim_version="$NVIM_VERSION"
|
||||||
echo "neovim_version: \"$neovim_version\""
|
echo "neovim_version: \"$neovim_version\""
|
||||||
|
|
||||||
|
14
src_files/.local/bin/.tmux-session-hydrate
Normal file
14
src_files/.local/bin/.tmux-session-hydrate
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
#!/bin/zsh
|
||||||
|
|
||||||
|
local omitted_dirs=(
|
||||||
|
$HOME
|
||||||
|
$HOMEBOX
|
||||||
|
$DEVDIR
|
||||||
|
)
|
||||||
|
[[ ! ${omitted_dirs[(re)$(pwd)]} ]] &&
|
||||||
|
tmux new-window -d -n cmd &&
|
||||||
|
tmux rename-window $EDITOR &&
|
||||||
|
$EDITOR .
|
||||||
|
|
||||||
|
clear
|
||||||
|
|
@ -1,10 +0,0 @@
|
|||||||
#!/bin/zsh
|
|
||||||
|
|
||||||
if [[ "$(pwd)" == $HOME || "$(pwd)" == $HOMEBOX ]]; then
|
|
||||||
clear
|
|
||||||
return
|
|
||||||
fi
|
|
||||||
tmux new-window -dn scratch
|
|
||||||
vim .
|
|
||||||
clear
|
|
||||||
|
|
59
src_files/.local/bin/tmux-sessionizer
Normal file → Executable file
59
src_files/.local/bin/tmux-sessionizer
Normal file → Executable file
@ -1,49 +1,36 @@
|
|||||||
#!/bin/zsh
|
#!/bin/zsh
|
||||||
|
|
||||||
switch_to() {
|
switch_to() {
|
||||||
if [[ -z $TMUX ]]; then
|
[[ -z $TMUX ]] && tmux attach-session -t $1 || tmux switch-client -t $1
|
||||||
tmux attach-session -t $1
|
|
||||||
else
|
|
||||||
tmux switch-client -t $1
|
|
||||||
fi
|
|
||||||
}
|
}
|
||||||
|
|
||||||
has_session() {
|
tmux_session_exists() {
|
||||||
tmux list-sessions | grep -q "^$1:"
|
[[ -n $(pgrep tmux) ]] && tmux list-sessions | grep -q "^$1:"
|
||||||
}
|
}
|
||||||
|
|
||||||
hydrate() {
|
hydrate() {
|
||||||
if [ -f $2/.tmux-sessionizer ]; then
|
local tmux_hydrate_path="$HOME/.local/bin/.tmux-session-hydrate"
|
||||||
tmux send-keys -t $1 "source $2/.tmux-session-setup" c-M
|
[[ -f $2/.tmux-session-hydrate ]] && tmux_hydrate_path="$2/.tmux-session-hydrate"
|
||||||
elif [ -f $HOME/.tmux-sessionizer ]; then
|
[[ -f $tmux_hydrate_path ]] && tmux send-keys -t $1 "source $tmux_hydrate_path" c-M
|
||||||
tmux send-keys -t $1 "source $HOME/.tmux-session-setup" c-M
|
|
||||||
fi
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if [[ $# -eq 1 ]]; then
|
local search_dirs=(
|
||||||
selected=$1
|
$HOME
|
||||||
else
|
$HOMEBOX
|
||||||
# If someone wants to make this extensible, i'll accept
|
$DEVDIR
|
||||||
# PR
|
$DEVDIR/git
|
||||||
selected=$(find ~/ ~/personal ~/personal/dev/env/.config -mindepth 1 -maxdepth 1 -type d | fzf)
|
$DEVDIR/git/me
|
||||||
fi
|
$DEVDIR/git/gary
|
||||||
|
$DEVDIR/git/other
|
||||||
|
)
|
||||||
|
local selected_path=''
|
||||||
|
[[ $# -eq 1 ]] && selected_path=$1 ||
|
||||||
|
selected_path=$(find $search_dirs -mindepth 1 -maxdepth 1 -type d | fzf)
|
||||||
|
[[ -z $selected_path ]] && exit 0
|
||||||
|
|
||||||
if [[ -z $selected ]]; then
|
local selected_name=$(basename "$selected_path" | tr . _)
|
||||||
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
|
|
||||||
|
|
||||||
|
! (tmux_session_exists $selected_name) &&
|
||||||
|
tmux new-session -d -s $selected_name -c $selected_path &&
|
||||||
|
hydrate $selected_name $selected_path
|
||||||
switch_to $selected_name
|
switch_to $selected_name
|
||||||
|
Loading…
Reference in New Issue
Block a user