-
Notifications
You must be signed in to change notification settings - Fork 80
feat: add SESH_SESSION_NAME environment variable #225
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add SESH_SESSION_NAME environment variable #225
Conversation
When creating new tmux sessions, sesh now automatically sets the SESH_SESSION_NAME environment variable to the name of the session. This enables scripts and programs to know the current session name. - Add -e SESH_SESSION_NAME to tmux new-session command - Document the new feature in README.md under Environment Variables section
|
Do you have an example of how you'd use it? You can run the following command to get the name of the current session: tmux display-message -p '#S' |
|
My goal is make copies of ~/.kube/config so I can have a per-session kubeconfig. As setting "current" context and namespace changes the config file. having the session name will allow for this config. Fetching the session name from tmux is ok, but would bind any scripting to HAVE to be running under tmux, which is most cases would be true, but less flexible. |
|
I understand and have some feedback:
Thanks for suggesting this feature, let me know your thoughts. |
That's your call :-)
That's exactly the point. One of the benefits I see of having multiple sessions, as opposed to tmux windows, is you can isolate environments and env vars in each session. I could see situations where multiple env vars would want to be set for any given session, not just the session name.
I would say no more risk than the
Working on getting this to work right now. This is hooked with The order of when hooks get run and when the shell is started is not clear. also, it seems on the Still working on it, lol |
joshmedeski
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for discussing this with me. I'm alright with shipping it!
|
TIL tmux hooks! Here is per-session KUBECONFIG. Didn't even need the PR. #!/usr/bin/env bash
# tmux set-hook -g session-created 'run-shell "<this script> start #{hook_session_name}"'
# tmux set-hook -g session-closed 'run-shell "<this script> stop #{hook_session_name}"'
if [ $# -ne 2 ]; then
echo "Usage: $0 [start|stop] <session_name>"
exit 1
fi
SESSION_NAME=$2
CLEANED_SESSION_NAME=$(echo $SESSION_NAME | tr -cd '[:alnum:]')
KUBECONFIG_PATH=~/.kube/config-${CLEANED_SESSION_NAME}
case "$1" in
start)
cp ~/.kube/config $KUBECONFIG_PATH
tmux setenv -t ${SESSION_NAME} KUBECONFIG $KUBECONFIG_PATH
;;
stop)
if [ -f $KUBECONFIG_PATH ]; then
rm $KUBECONFIG_PATH
fi
;;
*)
echo "Invalid argument. Usage: $0 [start|stop]"
exit 1
;;
esac
Then in zsh you need: if [ -n "$TMUX" ]; then
function refresh {
export $(tmux show-environment | grep "^KUBECONFIG") > /dev/null
}
else
function refresh { }
fi
function preexec {
refresh
}Then you can |
|
Hmmm, I thought this kind of feature didn't need to be tied to sesh. I might decide to revert it |
|
Makes sense. |
When creating new tmux sessions, sesh now automatically sets the SESH_SESSION_NAME environment variable to the name of the session. This enables scripts and programs to know the current session name.
Add -e SESH_SESSION_NAME to tmux new-session command
Document the new feature in README.md under Environment Variables section