Skip to content

feat: send session_name to scripts that need it - #405

Open
abourjac wants to merge 1 commit into
dracula:masterfrom
abourjac:send_session_name
Open

abourjac wants to merge 1 commit into
dracula:masterfrom
abourjac:send_session_name

Conversation

@abourjac

Copy link
Copy Markdown
Contributor

git.sh, cwd.sh, etc, are trying to display data about the current active pane. However, with how it is handled today, having two different sessions live with two different panes would show erroneous data in one of them since the scrips cannot know in which session they are running.
It can be fixed by using #{session_name} to find the active pane in the right session.

Assisted-by: Claude Sonnet 5

@Theoreticallyhugo

Copy link
Copy Markdown
Collaborator

I wanna see this merged, but I found some bugs, and I'll need some time to compile them into good feedback. I hope it won't take long.

@Theoreticallyhugo Theoreticallyhugo left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I commented on one line, but this applies to all other lines like it.
I am also not done yet, but probably won't be able to post the rest of the review today.

Since you're using AI as co-author, you might wanna ask it to check your PR for bugs and such.

Comment thread scripts/dracula.sh Outdated
if [[ -x "${current_dir}/${script}" ]]; then
IFS=' ' read -r -a colors <<<$(get_tmux_option "@dracula-custom-plugin-colors" "cyan dark_gray")
script="#($current_dir/${script})"
script="#($current_dir/${script} #{session_name})"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Passing session_name like this seems to word-split, meaning the two sessions "test proj1" and "test proj2" clash.

Passing as #{q:session_name} should fix this problem for the most part.

q: is specific to tmux.
It is roughly documented in (the manpages](https://man.openbsd.org/tmux#FORMATS).
At the time of writing, the following characters are escaped:
| & ; < > ( ) { } $ \ " ' * ? [ # space = % \n \t`
Find this on line 4462 in the tmux source

Also, from what i can tell, not quoting with q: means the session name is evaluated. This is somewhat dangerous. For me running tmux rename-session 'x$(touch /tmp/PWNED)y' actually places a file there. So, naming your session after removing the french language pack could cause tears.

@abourjac abourjac Sep 30, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right. I went with #{q:session_id} which is safer and fixes other issues as you noted.
Also dropped list-panes -f that doesn't exists before nuxt 3.2

@Theoreticallyhugo Theoreticallyhugo left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found some things that need fixing in this PR, and some that I'll put into issues.
Let me know if you got any questions or objections.

Comment thread scripts/cwd.sh Outdated
Comment on lines +8 to +13
local session="$1"
if [ -n "$session" ]; then
tmux list-panes -t "$session" -f '#{pane_active}' -F "#{pane_current_path}" 2>/dev/null
else
tmux list-panes -f '#{pane_active}' -F "#{pane_current_path}" 2>/dev/null
fi

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this requires the session_name as first argument to the script, this should be documented (at the start of the script i'd argue, but i'm open to other ideas)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, documented in usage header(s)

Comment thread scripts/cwd.sh Outdated
Comment on lines 17 to 26

@Theoreticallyhugo Theoreticallyhugo Sep 30, 2026 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the path is empty (which can happen for a variety of semi rare reasons), this widget displays a bare ~. This is a bug generally unrelated to this PR, because /tmp is changed to ~/tmp too. So, I'll have to open an issue/ PR for that.

#411

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nevertheless it might be good to think about failed path resolutions.

The following two are probably acceptable failure modes

  • Pane is on path that has been deleted
    • cwd just shows the old path, and others tend to just fail. I guess thats fine
  • script is run with session name resolved earlier, but session name has changed since (a very rare race)
    • this can be fixed by passing session_id instead
    • if this ever happens, it should be visible til the next pane update only, so i dont think this is really relevant.

However, we don't get feedback if we expect to get your new fix, but $1 is empty or never passed, because we fall back to the old, unfixed, method without feedback. We might wanna document this in a docstring in a the function.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, fallback kept (if script is run by hand, without dracula.sh passing $1) and documented.

Comment thread scripts/dracula.sh Outdated
if [[ -x "${current_dir}/${script}" ]]; then
IFS=' ' read -r -a colors <<<$(get_tmux_option "@dracula-custom-plugin-colors" "cyan dark_gray")
script="#($current_dir/${script})"
script="#($current_dir/${script} #{session_name})"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change passes the session name to all custom scripts as $1.
This contract change must be documented in docs/CONFIG.md

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Documented in the custom:script-name section.

…t current active pane

Assisted-by: Claude Code (Claude Sonnet 5, Claude Opus 5.5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants