41 lines
1.3 KiB
Bash
Executable file
41 lines
1.3 KiB
Bash
Executable file
# Function to change the tmux window background color based on SSH environment
|
|
function windowc() {
|
|
local profile_name="$1"
|
|
|
|
case "$profile_name" in
|
|
services*|service*)
|
|
tmux set-window-option -g window-status-bg colour1 # Change to the desired color
|
|
;;
|
|
production*|prod*|web*)
|
|
tmux set-window-option -g window-status-bg "rgb:00/7F/7F" # Change to the desired color
|
|
;;
|
|
staging*|stage*)
|
|
tmux set-window-option -g window-status-bg colour3 # Change to the desired color
|
|
;;
|
|
*)
|
|
tmux set-window-option -g window-status-bg default # Use default color for any other server
|
|
;;
|
|
esac
|
|
}
|
|
|
|
# Function to automatically create a new tmux window when using ssh
|
|
function colourssh() {
|
|
# Run the original ssh command, capturing its output
|
|
ssh_output=$(command ssh "$@")
|
|
|
|
# Check if the ssh command was successful
|
|
if [ $? -eq 0 ]; then
|
|
# Extract the hostname from the ssh command using pcregrep
|
|
host=$(echo "$ssh_output" | pcregrep -o1 'ssh\s+([^\@]+)')
|
|
|
|
# Change tmux window background color based on SSH environment
|
|
windowc "$host"
|
|
|
|
# Create a new tmux window
|
|
tmux new-window
|
|
fi
|
|
}
|
|
|
|
# Alias to use the modified ssh function
|
|
alias ssh="colourssh"
|
|
|