From ac5ce1fbe633edb4fb70341a57b8f67dc277b775 Mon Sep 17 00:00:00 2001 From: Tomasz Kapias Date: Sun, 19 Mar 2023 15:08:59 +0700 Subject: [PATCH] moved tmux before sourcing --- .bashrc | 10 ++++++++++ .bashrc.d/10-aliases.bashrc | 33 +++++++++++++++++---------------- .bashrc.d/11-functions.bashrc | 10 ---------- .bashrc.d/99-autostart.bashrc | 14 ++++---------- 4 files changed, 31 insertions(+), 36 deletions(-) diff --git a/.bashrc b/.bashrc index 535c5e0..8000c7b 100644 --- a/.bashrc +++ b/.bashrc @@ -10,6 +10,16 @@ esac chmod 700 ~/.bashrc.d chmod 600 ~/.bashrc ~/.bashrc.d/* +# check if we are already in a Tmux session or open/attach the default one +if [[ "${TERM-}" != tmux* ]] && [[ -z "${TMUX}" ]] && [[ -z "${SSH_CONNECTION}" ]] && command -v tmux 1> /dev/null; then + # open/attach the local default Tmux session + systemd-run -q --scope --user --unit tmux-session-local tmux new-session -A -s local && exit +elif [[ -z "${TMUX}" ]] && [[ -n "${SSH_CONNECTION}" ]] && command -v tmux 1> /dev/null; then + # open/attach the SSH default Tmux session + systemd-run -q --scope --user --unit tmux-session-ssh tmux new-session -A -s ssh && exit +fi + +# if Tmux is not installed or if we are inside a Tmux session continue the sourcing for file in ~/.bashrc.d/*.bashrc; do source "${file}" diff --git a/.bashrc.d/10-aliases.bashrc b/.bashrc.d/10-aliases.bashrc index b4aa2ee..68316fc 100644 --- a/.bashrc.d/10-aliases.bashrc +++ b/.bashrc.d/10-aliases.bashrc @@ -23,7 +23,7 @@ else alias grep='grep -a' fi -# most common usage of df/du +# most common usage of df/du if command -v hl 1> /dev/null; then alias df='df -Tha --total | hlauto --df' else @@ -31,7 +31,7 @@ else fi alias du='du -ach' -# better ncdu +# better ncdu if command -v ncdu 1> /dev/null; then alias ncdu='ncdu -e --exclude-kernfs --color dark' fi @@ -100,7 +100,7 @@ if command -v xclip 1> /dev/null; then # shortcuts to copy/paste text contents alias xclip-in-txt='xclip -in -rmlastnl -selection clipboard' alias xclip-txt-out='xclip -out -rmlastnl -selection clipboard' - # shortcuts to copy/paste other contents + # shortcuts to copy/paste other contents alias xclip-in-png='xclip -in -selection clipboard -t image/png' alias xclip-in-jpeg='xclip -in -selection clipboard -t image/jpeg' alias xclip-in-gif='xclip -in -selection clipboard -t image/gif' @@ -137,15 +137,16 @@ if command -v et 1> /dev/null; then alias etmotd='et --ssh-option SetEnv=SSH_MOTD=1' fi -# open a new tmux session named ssh_tmux or attach to it +# open/attach to a default tmux session named local or ssh if command -v tmux 1> /dev/null; then - alias tmuxs='tmux new-session -A -s ssh_tmux && exit' + alias tmux-local='systemd-run -q --scope --user --unit tmux-session-local tmux new-session -A -s local && exit' + alias tmux-ssh='systemd-run -q --scope --user --unit tmux-session-ssh tmux new-session -A -s ssh && exit' fi # vifm: tui file explorer if command -v vifmrun 1> /dev/null && command -v vifm 1> /dev/null; then - alias vifm='vifmrun' - alias vf='vifmrun' + alias vifm='vifmrun' + alias vf='vifmrun' fi # dragon for drag&drop function @@ -156,11 +157,11 @@ fi # glow: tui/cli markdown pager explorer if command -v glow 1> /dev/null; then - alias glw='glow -l -p -w 80 -s dark' + alias glw='glow -l -p -w 80 -s dark' fi if command -v tidy-viewer 1> /dev/null; then - alias tv='tidy-viewer' + alias tv='tidy-viewer' fi # HLEDGER @@ -173,24 +174,24 @@ alias meteo='echo -e "┌─────────┐\n│ wttr.in │ ${MYCIT # mimic3: tts interactive command, just paste text inside if command -v mimic3 1> /dev/null; then - alias mimic3-fr='mimic3 --voice fr_FR/tom_low --play-program paplay --interactive' - alias mimic3-en='mimic3 --voice en_US/ljspeech_low --play-program paplay --interactive' - alias mimic3-pl='mimic3 --voice pl_PL/m-ailabs_low --play-program paplay --interactive' + alias mimic3-fr='mimic3 --voice fr_FR/tom_low --play-program paplay --interactive' + alias mimic3-en='mimic3 --voice en_US/ljspeech_low --play-program paplay --interactive' + alias mimic3-pl='mimic3 --voice pl_PL/m-ailabs_low --play-program paplay --interactive' fi # Neomutt, notmuch, mbsync if command -v neomutt 1> /dev/null; then alias ntt='neomutt -f "📫Boite à lettres"' if command -v notmuch 1> /dev/null && command -v mbsync 1> /dev/null; then - # Sync all Mailboxes, Notmuch and Afew, then launch Neomutt + # Sync all Mailboxes, Notmuch and Afew, then launch Neomutt alias ntt-sync='notmuch new && mbsync mutt && notmuch new && neomutt -f "📫Boite à lettres"' - # Sync some Mailboxes, Notmuch and Afew, then launch Neomutt + # Sync some Mailboxes, Notmuch and Afew, then launch Neomutt alias ntt-sync-base='notmuch new && mbsync mutt-fast && notmuch new && neomutt -f "📫Boite à lettres"' - # Reindex Notmuch and Afew for main, then launch Neomutt + # Reindex Notmuch and Afew for main, then launch Neomutt alias ntt-index='notmuch new && neomutt -f "📫Boite à lettres"' fi if command -v msmtp-queue 1> /dev/null; then - # Flush send mail queue with msmtpq, then launch Neomutt + # Flush send mail queue with msmtpq, then launch Neomutt alias ntt-flush='msmtp-queue -r && neomutt -f "📫Boite à lettres"' fi fi diff --git a/.bashrc.d/11-functions.bashrc b/.bashrc.d/11-functions.bashrc index faa3caa..14e8da6 100644 --- a/.bashrc.d/11-functions.bashrc +++ b/.bashrc.d/11-functions.bashrc @@ -86,16 +86,6 @@ c() { fi } -# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -# shortcut for tmux to open a new default session with a name or attach if it exist -# an alias tmuxs exist too for ssh sessions -if command -v tmux 1> /dev/null; then - tmuxa() { - systemd-run -q --scope --user tmux new-session -A -s default "$@" - exit - } -fi - # ============================== # Utils # ============================== diff --git a/.bashrc.d/99-autostart.bashrc b/.bashrc.d/99-autostart.bashrc index 3cb6f68..c91e478 100644 --- a/.bashrc.d/99-autostart.bashrc +++ b/.bashrc.d/99-autostart.bashrc @@ -5,16 +5,10 @@ # AUTOSTART # ============================== -# run tmux if TMUX variable is null -if [[ "${TERM-}" != tmux* ]] && [[ -z "${TMUX}" ]] && [[ -z "${SSH_CONNECTION}" ]]; then - tmuxa -elif [[ -z "${TMUX}" ]] && [[ -n "${SSH_CONNECTION}" ]]; then - tmuxs -fi -# run MOTD at login only in an ssh session +# run MOTD at login only in an ssh session containing the env $SSH_MOTD=1 if [[ -n "${TMUX}" ]] && [[ -n "${SSH_CONNECTION}" ]] && [[ "${SSH_MOTD-}" == 1 ]] && [[ -f "/etc/update-motd.d/00-motdfetch" ]]; then - motd + motd else - # use function pgdown to get the prompt to terminal window bottom - pgdown + # use function pgdown to get the prompt to terminal window bottom + pgdown fi