Skip to content

Instantly share code, notes, and snippets.

@myuon
Last active July 18, 2016 02:47
Show Gist options
  • Save myuon/2e6068810fbd8a97885eca513cf71506 to your computer and use it in GitHub Desktop.
Save myuon/2e6068810fbd8a97885eca513cf71506 to your computer and use it in GitHub Desktop.
.zshrc
#
# Executes commands at the start of an interactive session.
#
# Authors:
# Sorin Ionescu <[email protected]>
#
# Source Prezto.
if [[ -s "${ZDOTDIR:-$HOME}/.zprezto/init.zsh" ]]; then
source "${ZDOTDIR:-$HOME}/.zprezto/init.zsh"
fi
# Customize to your needs...
path=($HOME/.linuxbrew/bin(N-/) $path)
path=($HOME/.local/bin(N-/) $path)
export PATH="/home/rick/.linuxbrew/sbin:$PATH"
if [[ -r ~/.local/lib/python3.5/site-packages/powerline/bindings/zsh/powerline.zsh ]]; then
source ~/.local/lib/python3.5/site-packages/powerline/bindings/zsh/powerline.zsh
fi
alias ghc="stack ghc"
alias ghci="stack ghci"
alias runghc="stack runghc"
alias runhaskell="stack runghc"
autoload -Uz promptinit
promptinit
prompt sorin
function is_exists() { type "$1" >/dev/null 2>&1; return $?; }
function is_osx() { [[ $OSTYPE == darwin* ]]; }
function is_screen_running() { [ ! -z "$STY" ]; }
function is_tmux_runnning() { [ ! -z "$TMUX" ]; }
function is_screen_or_tmux_running() { is_screen_running || is_tmux_runnning; }
function shell_has_started_interactively() { [ ! -z "$PS1" ]; }
function is_ssh_running() { [ ! -z "$SSH_CONECTION" ]; }
function tmux_automatically_attach_session()
{
if is_screen_or_tmux_running; then
! is_exists 'tmux' && return 1
if is_tmux_runnning; then
echo "${fg_bold[red]} _____ __ __ _ ___ __ ${reset_color}"
echo "${fg_bold[red]}|_ _| \/ | | | \ \/ / ${reset_color}"
echo "${fg_bold[red]} | | | |\/| | | | |\ / ${reset_color}"
echo "${fg_bold[red]} | | | | | | |_| |/ \ ${reset_color}"
echo "${fg_bold[red]} |_| |_| |_|\___//_/\_\ ${reset_color}"
elif is_screen_running; then
echo "This is on screen."
fi
else
if shell_has_started_interactively && ! is_ssh_running; then
if ! is_exists 'tmux'; then
echo 'Error: tmux command not found' 2>&1
return 1
fi
if tmux has-session >/dev/null 2>&1 && tmux list-sessions | grep -qE '.*]$'; then
# detached session exists
tmux list-sessions
echo -n "Tmux: attach? (y/N/num) "
read
if [[ "$REPLY" =~ ^[Yy]$ ]] || [[ "$REPLY" == '' ]]; then
tmux attach-session
if [ $? -eq 0 ]; then
echo "$(tmux -V) attached session"
return 0
fi
elif [[ "$REPLY" =~ ^[0-9]+$ ]]; then
tmux attach -t "$REPLY"
if [ $? -eq 0 ]; then
echo "$(tmux -V) attached session"
return 0
fi
fi
fi
if is_osx && is_exists 'reattach-to-user-namespace'; then
# on OS X force tmux's default command
# to spawn a shell in the user's namespace
tmux_config=$(cat $HOME/.tmux.conf <(echo 'set-option -g default-command "reattach-to-user-namespace -l $SHELL"'))
tmux -f <(echo "$tmux_config") new-session && echo "$(tmux -V) created new session supported OS X"
else
tmux new-session && echo "tmux created new session"
fi
fi
fi
}
tmux_automatically_attach_session
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment