diff options
author | Julio Capote <jcapote@gmail.com> | 2018-11-06 02:49:16 +0000 |
---|---|---|
committer | Julio Capote <jcapote@gmail.com> | 2018-11-06 02:49:16 +0000 |
commit | a62a3e7755579d93ce3a87243dd277575930fffe (patch) | |
tree | 6d074f7294c5b7a45bed7ac229a6802830da2a04 /content/post/2014-02-24-tmux-session-coloring.markdown | |
download | capotej.com-a62a3e7755579d93ce3a87243dd277575930fffe.tar.gz |
init
Diffstat (limited to '')
-rw-r--r-- | content/post/2014-02-24-tmux-session-coloring.markdown | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/content/post/2014-02-24-tmux-session-coloring.markdown b/content/post/2014-02-24-tmux-session-coloring.markdown new file mode 100644 index 0000000..425648a --- /dev/null +++ b/content/post/2014-02-24-tmux-session-coloring.markdown @@ -0,0 +1,40 @@ +--- +layout: post +title: "Tmux session coloring" +date: 2014-02-24 08:30 +date: 2014-02-24T00:00:00Z +comments: true +tags: ["shell scripting", "tmux"] +--- + +Recently, I've really gotten into tmux for managing all my terminal sessions/windows. Not so much for the panes, but more for keeping a highly contextual environment per project or task. + +As the number of sessions grew, they became difficult to tell apart. For a few days now, I've had the idea of hashing the name of the session into a unique color, so that every session had its own `status-bg` color. + +First, the `tmuxHashColor` function: + +```sh +tmuxHashColor() { + local hsh=$(echo $1 | cksum | cut -d ' ' -f 1) + local num=$(expr $hsh % 255) + echo "colour$num" +} +``` + +In our `ns` function (new session), we hash the supplied session name to a color, then use `tmux send-keys` to set its `status-bg` color to it: + +```sh +ns() { + if [ -z $1 ]; then + 1=$(basename $(pwd)) + fi + tmux new-session -d -s $1 + local color=$(tmuxHashColor $1) + tmux send-keys -t $1 "tmux set-option status-bg $color" C-m + tmux send-keys -t $1 "clear" C-m + tmux attach -t $1 +} + +``` + +Now every session has it's own distinct `status-bg` color! |