Created
May 7, 2015 23:14
-
-
Save manuel-colmenero/db540bfb116bf5868599 to your computer and use it in GitHub Desktop.
Tmux scripts sample
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
rtmux() { | |
echo -ne "\033]0;mcg@$1\007" # Set window title | |
ssh $1 -t 'tmux attach -t mcg || tmux -f ~/mcg-tmux.conf --login new-session -s mcg' | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# Manuel Colmenero © 2014 | |
# | |
export SESSION_PATH=~/src/dotfiles/ | |
export CDPATH=".:$SESSION_PATH" | |
cd $SESSION_PATH | |
xargs tmux >/dev/null <<TMUX | |
set-environment CDPATH "$CDPATH"; | |
set-environment SESSION_PATH "$SESSION_PATH"; | |
set-option status-left " #S#(tmux-git-status '$SESSION_PATH') "; | |
set-option default-path "$SESSION_PATH"; | |
new-window -n "wiki" "vim-wiki dotfiles"; | |
source-file "$HOME/.etc/tmux_layouts.d/git"; | |
select-window -t 1; | |
TMUX | |
exec bash --login |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
new-window -n 'git' 'git watch' | |
split-window 'git console' | |
if-shell "[ '#{session_width}' -ge 120 ]" \ | |
"select-layout even-horizontal" \ | |
"select-layout even-vertical" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# Returns a formatted string for use in tmux statusline. | |
# | |
# Manuel Colmenero © 2015 | |
# | |
path=$1 | |
if [ -z "$path" ] || [ ! -d "$path" ] || [ ! -d "$path/.git" ]; then | |
echo Argument needed: path. >&2 | |
exit 1 | |
fi | |
cd "$path" | |
status=$(git rev-parse --abbrev-ref HEAD) | |
changes=$(git status --porcelain | awk '{ print $1 }' | cut -c 1 | sort -u | xargs echo | sed 's/ //g') | |
if [ -n "$changes" ]; then | |
status="$status,$changes" | |
fi | |
origin=$(git rev-parse --abbrev-ref --symbolic-full-name @{u} 2>/dev/null) | |
if [ "$origin" = '@{u}' ]; then | |
status="$status,??" | |
else | |
number=$(git rev-list HEAD ^$origin 2>/dev/null | wc -l) | |
if [ "$number" != "0" ]; then | |
status="$status,+$number" | |
fi | |
number=$(git rev-list ^HEAD $origin 2>/dev/null | wc -l) | |
if [ "$number" != "0" ]; then | |
status="$status,-$number" | |
fi | |
fi | |
echo "[$status]" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
OLD_SESSION="`tmux display-message -p '#S'`" | |
tmux switch-client -n | |
tmux kill-session -t "$OLD_SESSION" | |
tmux display-message "Deleted session: $OLD_SESSION" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
_TMUX_LAYOUT_DIRS=~/.etc/tmux_layouts.d | |
LAYOUT=$1 | |
if [ -z "$LAYOUT" ]; then | |
echo "Please specify a layout name." | |
exit 1 | |
fi | |
exec tmux source-file $_TMUX_LAYOUT_DIRS/$LAYOUT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# Manuel Colmenero © 2013 | |
# | |
if ! which tmux 2>&1 >/dev/null; then | |
echo "tmux is not installed on the system." | |
exit 1 | |
fi | |
# Execute getopt | |
ARGS=$(getopt -o "ul" -l "unicode,list" -n "$0" -- "$@"); | |
eval set -- "$ARGS"; | |
while true; do | |
case "$1" in | |
-u|--unicode) | |
shift; | |
unicode=-u | |
;; | |
-l|--list) | |
shift; | |
list=1 | |
;; | |
--) | |
shift; | |
break; | |
;; | |
esac | |
done | |
if test $list; then | |
tmux_sessions=$(mktemp) | |
tmux ls 2>/dev/null 1>$tmux_sessions | |
cat $tmux_sessions | |
exclude=$(cat $tmux_sessions | sed 's/^\([^:]\+\):.*$/\1/g' | xargs echo | sed 's/ /\\|/g') | |
ls -1 $HOME/.etc/tmux_sessions.d/ | sed 's/\.sh$//' | grep -v "^\\($exclude\\)$" | |
rm $tmux_sessions | |
exit 0 | |
fi | |
target=$1 | |
command="$HOME/.etc/tmux_sessions.d/$target.sh" | |
if ! test -x "$command"; then | |
command= | |
fi | |
if ! tmux has-session -t "$target" 2>/dev/null; then | |
TMUX= tmux $unicode new-session -d -s "$target" $command | |
fi | |
if test "$TMUX"; then | |
exec tmux switch-client -t "$target" | |
else | |
exec tmux $unicode attach-session -t "$target" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment