From fa12698c99eed4efcddb2b0a229d042bc0a680b6 Mon Sep 17 00:00:00 2001 From: Nikolas Weger Date: Fri, 6 Dec 2019 10:18:19 +0100 Subject: [PATCH] updated stuff --- zsh/.zshrc | 1 + zsh/libraries/tmux/tmux-extra.conf | 2 + zsh/libraries/tmux/tmux.conf | 1 + zsh/libraries/tmux/tmux.zsh | 100 +++++++++++++++++++++++++++++ 4 files changed, 104 insertions(+) create mode 100644 zsh/libraries/tmux/tmux-extra.conf create mode 100644 zsh/libraries/tmux/tmux.conf create mode 100644 zsh/libraries/tmux/tmux.zsh diff --git a/zsh/.zshrc b/zsh/.zshrc index fb7d55c..b8b9256 100644 --- a/zsh/.zshrc +++ b/zsh/.zshrc @@ -4,6 +4,7 @@ fi source "$ZDOTDIR/libraries/export.zsh" source "$ZDOTDIR/libraries/dircolor.zsh" +source "$ZDOTDIR/tmux/tmux.zsh" source "/usr/share/zsh/plugins/zsh-autosuggestions/zsh-autosuggestions.zsh" source "/usr/share/zsh-theme-powerlevel10k/powerlevel10k.zsh-theme" diff --git a/zsh/libraries/tmux/tmux-extra.conf b/zsh/libraries/tmux/tmux-extra.conf new file mode 100644 index 0000000..b480373 --- /dev/null +++ b/zsh/libraries/tmux/tmux-extra.conf @@ -0,0 +1,2 @@ +set -g default-terminal $ZSH_TMUX_TERM +source-file $ZSH_TMUX_CONFIG diff --git a/zsh/libraries/tmux/tmux.conf b/zsh/libraries/tmux/tmux.conf new file mode 100644 index 0000000..0734df3 --- /dev/null +++ b/zsh/libraries/tmux/tmux.conf @@ -0,0 +1 @@ +set -g default-terminal $ZSH_TMUX_TERM diff --git a/zsh/libraries/tmux/tmux.zsh b/zsh/libraries/tmux/tmux.zsh new file mode 100644 index 0000000..272ba89 --- /dev/null +++ b/zsh/libraries/tmux/tmux.zsh @@ -0,0 +1,100 @@ +if ! (( $+commands[tmux] )); then + print "zsh tmux plugin: tmux not found. Please install tmux before using this plugin." >&2 + return 1 +fi + +# ALIASES + +alias ta='tmux attach -t' +alias tad='tmux attach -d -t' +alias ts='tmux new-session -s' +alias tl='tmux list-sessions' +alias tksv='tmux kill-server' +alias tkss='tmux kill-session -t' + +# CONFIGURATION VARIABLES +# Automatically start tmux +: ${ZSH_TMUX_AUTOSTART:=false} +# Only autostart once. If set to false, tmux will attempt to +# autostart every time your zsh configs are reloaded. +: ${ZSH_TMUX_AUTOSTART_ONCE:=true} +# Automatically connect to a previous session if it exists +: ${ZSH_TMUX_AUTOCONNECT:=true} +# Automatically close the terminal when tmux exits +: ${ZSH_TMUX_AUTOQUIT:=$ZSH_TMUX_AUTOSTART} +# Set term to screen or screen-256color based on current terminal support +: ${ZSH_TMUX_FIXTERM:=true} +# Set '-CC' option for iTerm2 tmux integration +: ${ZSH_TMUX_ITERM2:=false} +# The TERM to use for non-256 color terminals. +# Tmux states this should be screen, but you may need to change it on +# systems without the proper terminfo +: ${ZSH_TMUX_FIXTERM_WITHOUT_256COLOR:=screen} +# The TERM to use for 256 color terminals. +# Tmux states this should be screen-256color, but you may need to change it on +# systems without the proper terminfo +: ${ZSH_TMUX_FIXTERM_WITH_256COLOR:=screen-256color} +# Set the configuration path +: ${ZSH_TMUX_CONFIG:=$HOME/.tmux.conf} +# Set -u option to support unicode +: ${ZSH_TMUX_UNICODE:=false} + +# Determine if the terminal supports 256 colors +if [[ $terminfo[colors] == 256 ]]; then + export ZSH_TMUX_TERM=$ZSH_TMUX_FIXTERM_WITH_256COLOR +else + export ZSH_TMUX_TERM=$ZSH_TMUX_FIXTERM_WITHOUT_256COLOR +fi + +# Set the correct local config file to use. +if [[ "$ZSH_TMUX_ITERM2" == "false" && -e "$ZSH_TMUX_CONFIG" ]]; then + export ZSH_TMUX_CONFIG + export _ZSH_TMUX_FIXED_CONFIG="${0:h:a}/tmux.extra.conf" +else + export _ZSH_TMUX_FIXED_CONFIG="${0:h:a}/tmux.only.conf" +fi + +# Wrapper function for tmux. +function _zsh_tmux_plugin_run() { + if [[ -n "$@" ]]; then + command tmux "$@" + return $? + fi + + local -a tmux_cmd + tmux_cmd=(command tmux) + [[ "$ZSH_TMUX_ITERM2" == "true" ]] && tmux_cmd+=(-CC) + [[ "$ZSH_TMUX_UNICODE" == "true" ]] && tmux_cmd+=(-u) + + # Try to connect to an existing session. + [[ "$ZSH_TMUX_AUTOCONNECT" == "true" ]] && $tmux_cmd attach + + # If failed, just run tmux, fixing the TERM variable if requested. + if [[ $? -ne 0 ]]; then + if [[ "$ZSH_TMUX_FIXTERM" == "true" ]]; then + tmux_cmd+=(-f "$_ZSH_TMUX_FIXED_CONFIG") + elif [[ -e "$ZSH_TMUX_CONFIG" ]]; then + tmux_cmd+=(-f "$ZSH_TMUX_CONFIG") + fi + $tmux_cmd new-session + fi + + if [[ "$ZSH_TMUX_AUTOQUIT" == "true" ]]; then + exit + fi +} + +# Use the completions for tmux for our function +compdef _tmux _zsh_tmux_plugin_run +# Alias tmux to our wrapper function. +alias tmux=_zsh_tmux_plugin_run + +# Autostart if not already in tmux and enabled. +if [[ -z "$TMUX" && "$ZSH_TMUX_AUTOSTART" == "true" && -z "$INSIDE_EMACS" && -z "$EMACS" && -z "$VIM" ]]; then + # Actually don't autostart if we already did and multiple autostarts are disabled. + if [[ "$ZSH_TMUX_AUTOSTART_ONCE" == "false" || "$ZSH_TMUX_AUTOSTARTED" != "true" ]]; then + export ZSH_TMUX_AUTOSTARTED=true + _zsh_tmux_plugin_run + fi +fi +