From ddb070627747e77b178f13b0774e1ad3275e8e49 Mon Sep 17 00:00:00 2001 From: Huck Boles Date: Thu, 20 Jul 2023 07:24:02 -0500 Subject: [PATCH] merged: from desktop --- .zshrc | 2 +- include/aliases.zsh | 3 +++ include/zshmux.sh | 23 ++++++++++++----------- 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/.zshrc b/.zshrc index f4e4fbb..a7354c7 100644 --- a/.zshrc +++ b/.zshrc @@ -25,7 +25,7 @@ setopt append_create clobber_empty setopt hash_cmds hash_dirs setopt path_script prompt_subst setopt auto_param_keys auto_param_slash auto_remove_slash -setopt null_glob glob glob_dots glob_star_short bang_hist +setopt null_glob glob glob_dots glob_star_short bang_hist extendedglob unsetopt flow_control # completion diff --git a/include/aliases.zsh b/include/aliases.zsh index 9db5037..7b7e563 100644 --- a/include/aliases.zsh +++ b/include/aliases.zsh @@ -16,6 +16,7 @@ alias vdiff='nvim -d' alias sv='sudoedit' alias sudo="sudo " +alias .-='cd -' alias ..='cd ..' alias ...='cd ../..' alias ....='cd ../../..' @@ -25,6 +26,7 @@ alias j='jobs -l' alias c='clear' alias zc='cd;clear' alias cd='z ' +alias rename='perl-rename' alias make='make -j8 -l4 CFLAGS="-march=skylake -O2 -pipe -fomit-frame-pointer"' alias dust='dust -rb' @@ -38,6 +40,7 @@ alias lt='ls --tree' # color aliases alias ip='ip --color=auto' alias grep='grep --color=auto' +alias diff='diff --color' # tmux aliases alias tattach='tmux attach-session -t' diff --git a/include/zshmux.sh b/include/zshmux.sh index 0115284..b8041a0 100644 --- a/include/zshmux.sh +++ b/include/zshmux.sh @@ -1,38 +1,39 @@ #!/bin/bash -# start tmux server if it's not already running -[[ ! $(pgrep tmux) ]] && tmux start - # exit if already in a tmux session [[ -n $TMUX ]] && return +# start tmux server if it's not already running +[[ ! $(pgrep tmux) ]] && tmux start + # check if any sessions exit if [[ $(tmux list-sessions | wc -l) -ne 0 ]]; then - if [[ $(tmux list-sessions -F"#{?session_attached,,x}" | grep "x" | wc -l) -eq 1 ]] && [[ -z $SSH_CLIENT ]]; then - tmux attach-session -t $(tmux list-sessions -F"#{?session_attached,,#S}" ) + if [[ $(tmux list-sessions -F"#{?session_attached,,x}" | grep -c "x" ) -eq 1 ]] && [[ -z $SSH_CLIENT ]]; then + tmux attach-session -t "$(tmux list-sessions -F"#{?session_attached,,#S}" )" return else printf '\033[32;1mcurrent \033[33;1mtmux \033[32;1msessions\033[0m:\n' - tmux list-sessions -F"#S - (#{?session_attached,attached,not attached})" - printf '\033[34;1mattach session?\033[0;m: [\033[35;1mname\033[0m] \033[37;2m(empty if none)\033[0m: ' + # sed + echo is to highlight stars in green + echo -e "$(tmux list-sessions -F"#S #{?session_attached,*,}" | sed 's_\*_\\033[32;1m*\\033[0m_')" + printf '\033[34;1mattach or create\033[0;m \033[37;2m(empty if none)\033[0m: ' fi else printf '\033[34;1mno \033[33;1mtmux \033[34;1msessions active\n' - printf '\033[34;1mcreate new session?\033[0;m: [\033[35;1mname\033[0m] \033[37;2m(empty if none)\033[0m: ' + printf '\033[34;1mcreate new session?\033[0;m \033[37;2m(empty if none)\033[0m: ' fi -read session +read -r session # start requested session - since it uses grep you just have to put enough of a unique identifier to select if [[ -n $session ]]; then if tmux list-sessions -F"#S" | grep -q "$session"; then - tmux attach-session -t $session + tmux attach-session -t "$session" return elif [[ $session == new ]]; then tmux new-session return else - tmux new-session -s $session + tmux new-session -s "$session" return fi fi -- 2.45.2