From 306f4d1bb70c58584fd5230189bafe2dfb18a344 Mon Sep 17 00:00:00 2001 From: Juni Kim Date: Sat, 28 Jan 2023 10:05:19 -0500 Subject: [PATCH] tmuxs --- Makefile | 8 ++++++++ install_fedora.sh | 2 +- install_ubuntu.sh | 2 +- scripts/tmuxs | 51 +++++++++++++++++++++++++++++++++++++++++------ 4 files changed, 55 insertions(+), 8 deletions(-) create mode 100644 Makefile diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..5cbd170 --- /dev/null +++ b/Makefile @@ -0,0 +1,8 @@ +ubuntu: + docker run -it --rm -v $(CURDIR):/root/serverconfigs ubuntu /bin/bash + #docker run -it -v $(pwd):/root/serverconfigs --rm ubuntu /bin/bash + +fedora: + docker run -it --rm -v $(CURDIR):/root/serverconfigs fedora /bin/bash + +.PHONY: ubuntu fedora diff --git a/install_fedora.sh b/install_fedora.sh index d9cd6d9..4f786d0 100755 --- a/install_fedora.sh +++ b/install_fedora.sh @@ -64,7 +64,7 @@ dotfiles() { cp "$DIR/dots/zshrc" "$HOME/.zshrc" cp "$DIR/dots/tmux.conf" "$HOME/.tmux.conf" mkdir -p "$HOME/.local/bin" || exit 1 - cp -r "$DIR/scripts" "$HOME/.local/bin" || exit 1 + cp -r "$DIR/scripts/." "$HOME/.local/bin/" || exit 1 } neovim() { diff --git a/install_ubuntu.sh b/install_ubuntu.sh index eb86177..7d91ead 100755 --- a/install_ubuntu.sh +++ b/install_ubuntu.sh @@ -94,7 +94,7 @@ dotfiles() { cp "$DIR/dots/zshrc" "$HOME/.zshrc" cp "$DIR/dots/tmux.conf" "$HOME/.tmux.conf" mkdir -p "$HOME/.local/bin" || exit 1 - cp -r "$DIR/scripts" "$HOME/.local/bin" || exit 1 + cp -r "$DIR/scripts/." "$HOME/.local/bin/" || exit 1 } neovim() { diff --git a/scripts/tmuxs b/scripts/tmuxs index 302d7b3..2aaae7f 100755 --- a/scripts/tmuxs +++ b/scripts/tmuxs @@ -1,13 +1,48 @@ #!/usr/bin/env sh -WORKSPACES=${WORKSPACES:-$HOME/Documents} +WORKSPACES=${WORKSPACES:-$HOME/Documents:$HOME/docs/prg} IFS=':' findargs=$WORKSPACES -if test -z "$1"; then - sessiondir="$(find $findargs -maxdepth 2 -type d 2>/dev/null | fzf)" -else - sessiondir="$1" +while test $# -gt 0; do + case "$1" in + -d|--depth) + shift + if test -z "$1"; then + echo "No appropriate option given after depth" + exit 1 + else + depth="$1" + fi + shift; + ;; + -*) + echo "Invalid option $1" + exit 1 + ;; + *) + sessiondir="$1" + shift; + ;; + esac +done + +if test -z "$sessiondir"; then + if ! test -z "$depth" && test "$depth" -eq 0; then + sessiondir="$(find $findargs\ + \! -iwholename '*.git*'\ + \! -iwholename '*node_modules*'\ + \! -iwholename '*__pycache__*'\ + \! -iwholename '*venv*'\ + -type d 2>/dev/null | fzf)" + else + sessiondir="$(find $findargs -maxdepth ${depth:-2}\ + \! -iwholename '*.git*'\ + \! -iwholename '*node_modules*'\ + \! -iwholename '*__pycache__*'\ + \! -iwholename '*venv*'\ + -type d 2>/dev/null | fzf)" + fi fi if test -z "$sessiondir" || ! test -d "$sessiondir"; then @@ -23,5 +58,9 @@ else if ! tmux has-session -t="$name" 2> /dev/null; then tmux new-session -d -c "$sessiondir" -s "$name" fi - tmux switch-client -t "$name" + if test -z "$TMUX"; then + tmux attach -t "$name" + else + tmux switch-client -t "$name" + fi fi