Created
August 6, 2021 18:18
-
-
Save hexylena/bbedf13aac945fffffe517791d6ad18c to your computer and use it in GitHub Desktop.
Make spawning tmux sessions fun again
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
hash_string256() { | |
hash_value=$(printf "%s" "$1" | md5sum |tr -d " -"| tr "a-f" "A-F") | |
printf "ibase=16; (%s + %X) %% 100 \n" $hash_value "$2" | bc | |
} | |
declare -a light | |
light=(2 3 4 6 7 10 11 12 13 14 15 33 39 41 42 43 44 45 46 47 48 49 50 51 68 69 70 71 72 73 74 5 76 77 78 79 80 81 82 83 84 85 86 87 101 102 103 104 105 106 107 108 109 110 111 12 113 114 115 116 117 118 119 120 121 122 123 134 135 136 137 138 139 140 141 142 143 144 145 46 147 148 149 150 151 152 153 154 155 156 157 158 159 167 168 169 170 171 172 173 174 175 176 77 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 201 202 203 204 205 206 07 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 31 245 246 247 248 249 250 251 252 253 254 255) | |
if [[ "$1" != "" ]]; then | |
sesh="$1" | |
else | |
sesh="$(openssl rand -hex 4)" | |
fi | |
hashed=$(hash_string256 "$sesh") | |
if [[ " ${light[@]} " =~ " ${hashed} " ]]; then | |
bgcolor=black | |
else | |
bgcolor=white | |
fi | |
tmux list-session | grep --quiet "^${sesh}: " | |
session_exists=$? | |
if (( session_exists != 0 )); then | |
tmux new-session -s "$sesh" -d | |
fi | |
tmux set -t "$sesh" status-style bg=colour${hashed},fg=$bgcolor | |
#tmux send-keys -t "$sesh" "$sesh colour${hashed} $bgcolor" | |
tmux attach-session -t "$sesh" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment