improve tmux-sessionizer, make posix compatible
This commit is contained in:
parent
e1aa52a073
commit
59c107f4d4
1 changed files with 24 additions and 11 deletions
|
@ -1,20 +1,33 @@
|
||||||
#!/usr/bin/bash
|
#!/usr/bin/sh
|
||||||
|
|
||||||
HOMEDIR=~
|
HOMEDIR=~
|
||||||
which fd > /dev/null
|
which fd > /dev/null
|
||||||
if [ 0 = $? ]; then
|
if [ 0 = $? ]; then
|
||||||
SEL_DIR=$(fd . ~ --type directory | fzf) # if fd-find is installed
|
if [ -n "$1" ]; then
|
||||||
|
SEL_DIR=$(fd "$1" ~ --type directory | fzf) # if fd-find is installed
|
||||||
|
else
|
||||||
|
SEL_DIR=$(fd . ~ --type directory | fzf) # if fd-find is installed
|
||||||
|
fi
|
||||||
else
|
else
|
||||||
SEL_DIR=$(find ~ -not -path "*/.*" -type d -print 2>/dev/null | fzf)
|
if [ -n "$1" ]; then
|
||||||
|
SEL_DIR=$(find ~ -not -path "*/.*" -type d -name "$1" -print 2>/dev/null | fzf)
|
||||||
|
else
|
||||||
|
SEL_DIR=$(find ~ -not -path "*/.*" -type d -print 2>/dev/null | fzf)
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [ "$?" -ne 0 ]; then
|
||||||
|
exit
|
||||||
|
fi
|
||||||
|
|
||||||
SEL_NAME=$(basename "$SEL_DIR")
|
SEL_NAME=$(basename "$SEL_DIR")
|
||||||
|
|
||||||
new_session_name(){
|
new_session_name(){
|
||||||
RET=0
|
RET=0
|
||||||
while [[ $RET -eq 0 ]]; do
|
while [ $RET -eq 0 ]; do
|
||||||
clear
|
clear
|
||||||
read -p "New session name: " SEL_NAME
|
read -p "New session name: " SEL_NAME
|
||||||
if [[ -z "$SEL_NAME" ]]; then
|
if [ -z "$SEL_NAME" ]; then
|
||||||
clear
|
clear
|
||||||
else
|
else
|
||||||
RET=1
|
RET=1
|
||||||
|
@ -22,19 +35,19 @@ new_session_name(){
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
if [[ -z "$SEL_DIR" ]] || [[ -n "$SEL_DIR" ]] && [[ "$SEL_DIR" == "$HOMEDIR" ]]; then
|
if [ -z "$SEL_DIR" ] || [ -n "$SEL_DIR" ] && [ "$SEL_DIR" = "$HOMEDIR" ]; then
|
||||||
new_session_name
|
new_session_name
|
||||||
else
|
else
|
||||||
RET=0
|
RET=0
|
||||||
while [[ $RET -eq 0 ]]; do
|
while [ $RET -eq 0 ]; do
|
||||||
clear
|
clear
|
||||||
read -r -p "Choose a different session-name? [y/n] " USR_CHOICE
|
read -r -p "Choose a different session-name? [y/n] " USR_CHOICE
|
||||||
echo $USR_CHOICE
|
echo $USR_CHOICE
|
||||||
if [[ "$USR_CHOICE" == "y" ]]; then
|
if [ "$USR_CHOICE" = "y" ]; then
|
||||||
clear
|
clear
|
||||||
new_session_name
|
new_session_name
|
||||||
RET=1
|
RET=1
|
||||||
elif [[ "$USR_CHOICE" == "n" ]]; then
|
elif [ "$USR_CHOICE" = "n" ] || [ "$USR_CHOICE" = "" ]; then
|
||||||
clear
|
clear
|
||||||
RET=1
|
RET=1
|
||||||
else
|
else
|
||||||
|
@ -43,10 +56,10 @@ else
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
|
|
||||||
SEL_NAME=$(tr "[:lower:]" "[:upper:]" <<< "$SEL_NAME")
|
SEL_NAME=$(echo "$SEL_NAME" | tr "[:lower:]" "[:upper:]")
|
||||||
|
|
||||||
tmux new-session -d -s "$SEL_NAME" -c "$SEL_DIR"
|
tmux new-session -d -s "$SEL_NAME" -c "$SEL_DIR"
|
||||||
if [[ -e "$TMUX" ]]; then
|
if [ -e "$TMUX" ]; then
|
||||||
tmux switch-client -t "$SEL_NAME"
|
tmux switch-client -t "$SEL_NAME"
|
||||||
else
|
else
|
||||||
tmux attach -t "$SEL_NAME"
|
tmux attach -t "$SEL_NAME"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue