-
Notifications
You must be signed in to change notification settings - Fork 1
/
dotbash_tmux
132 lines (119 loc) · 3.43 KB
/
dotbash_tmux
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#!/bin/bash
#
# Alexs .bash configuration
#
# tmux configuration
# we supress TMUX to work nicely with TMATE
TMUX_SESSION_COUNT=`TMUX="" tmux list-sessions 2> /dev/null | wc -l`
if test $TMUX_SESSION_COUNT -gt 0; then
TMUX_SESSION_NAMES=`TMUX="" tmux ls | cut -d ':' -f 1 | sed ':a;N;$!ba;s/\n/ /g'`
fi
# Stop C-s triggering flow control
stty -ixon
if [[ `whoami` == "root" ]]; then
function sysmon()
{
if ! tmux has-session -t system; then
if which fish > /dev/null; then
tmux new-session -d -s system fish
else
tmux new-session -d -s system
fi
HTOPRC="${HOME}/.config/htop/${HOSTNAME}_htoprc"
if [ -e ${HTOPRC} ]; then
cp ${HTOPRC} "${HOME}/.config/htop/htoprc"
fi
tmux new-window -t system -n 'htop' 'htop'
tmux new-window -t system -n 'iotop' 'iotop -P -o -d 30'
if ! systemctl is-active --quiet powertop.service; then
tmux new-window -t system -n 'powertop' 'powertop'
fi
fi
tmux attach-session -t system
}
fi
# From: http://brainscraps.wikia.com/wiki/Renumbering_tmux_Windows
function tmux_renumber
{
for session in $(tmux ls | awk -F: '{print $1}') ;do
active_window=$(tmux lsw -t ${session} | awk -F: '/\(active\)$/ {print $1}')
inum=1
for window in $(tmux lsw -t ${session} | awk -F: '{print $1}') ;do
if [ ${window} -gt ${inum} ] ;then
echo "${session}:${window} -> ${session}:${inum}"
tmux movew -d -s ${session}:${window} -t ${session}:${inum}
fi
if [ ${window} = ${active_window} ] ;then
new_active_window=${inum}
fi
inum=$((${inum}+1))
done
tmux select-window -t ${session}:${new_active_window}
done
}
# Push the current window to the end of the stack
function tmux_push_to_end
{
focus_cmd=""
if [ "$1" == "" ]; then
active_window=$(tmux lsw | awk -F: '/\(active\)$/ {print $1}')
else
focus_cmd="-d"
active_window=$1
fi
inum=0
for window in $(tmux lsw | awk -F: '{print $1}') ;do
if [ ${window} -gt ${inum} ] ;then
inum=${window}
fi
done
tmux movew ${focus_cmd} -s ${active_window} -t $((${inum}+1))
}
# Attach or create a new session
function tmux_attach_or_new
{
session=$1
if [[ $TMUX == *tmate* ]]; then
TMUX="" tmux attach -d -t ${session}
else
tmux attach -d -t ${session} || tmux new -s ${session} fish
fi
}
alias tn="tmux_attach_or_new "
alias ta="tmux_attach_or_new "
# Get the Tmux Plugin Manager
function tmux_get_tpm
{
git clone https://github.com/tmux-plugins/tpm ~/.tmux/plugins/tpm
}
# Sync the environment of an existing shell
#
# tmux already updates the environment according to
# the update-environment settings in the config. However
# for existing shells you need to sync from from tmux's view
# of the world.
function tmux_sync_env
{
external_env=`tmux showenv | grep -v "^-"`
export ${external_env}
}
alias se="tmux_sync_env"
function tmux_set_name
{
tmux rename-window $(basename `pwd`)
}
if [[ $TMUX == *tmate* ]]; then
TMATE_MSG="inside TMATE"
function tmate_session
{
tmate show-messages | grep "Remote session:"
}
function tmate_ro_session
{
clear
tmate show-messages | grep "Remote session read only:"
}
fi
alias .tmux=". ~/.bash_tmux && TMUX="" tmux source-file ~/.tmux.conf 2> /dev/null"
echo "loading .bash_tmux ($TMUX_SESSION_COUNT sessions - $TMUX_SESSION_NAMES) $TMATE_MSG"
export USING_TMUX=1