Skip to content

#{pane_current_path} does not retain symlinked path #1282

Closed

Description

@sorsasampo

In shell:

$ mkdir real
$ ln -s real symlink
$ cd symlink
$ echo $PWD
/home/user/symlink

In tmux :display "#{pane_current_path}", result is: /home/user/real.

I would expect #{pane_current_path} to return the same as $PWD in the shell.

Debian Stretch/9.4, tmux -V 2.3, package 2.3-4.

Activity

  1. sorsasampo commented on Mar 14, 2018

    @sorsasampo
    Author

    Same result with tmux -V 2.6, package 2.6-3~bpo9+1.

  2. nicm commented on Mar 14, 2018

    @nicm
    Member
  3. sorsasampo commented on Mar 14, 2018

    @sorsasampo
    Author

    I guess the relevant code is here:

    tmux/format.c

    Lines 534 to 547 in 9fd9952

    /* Callback for pane_current_path. */
    static void
    format_cb_current_path(struct format_tree *ft, struct format_entry *fe)
    {
    struct window_pane *wp = ft->wp;
    char *cwd;
    if (wp == NULL)
    return;
    cwd = osdep_get_cwd(wp->fd);
    if (cwd != NULL)
    fe->value = xstrdup(cwd);
    }

    tmux/osdep-linux.c

    Lines 64 to 90 in 895f1d9

    char *
    osdep_get_cwd(int fd)
    {
    static char target[MAXPATHLEN + 1];
    char *path;
    pid_t pgrp, sid;
    ssize_t n;
    if ((pgrp = tcgetpgrp(fd)) == -1)
    return (NULL);
    xasprintf(&path, "/proc/%lld/cwd", (long long) pgrp);
    n = readlink(path, target, MAXPATHLEN);
    free(path);
    if (n == -1 && ioctl(fd, TIOCGSID, &sid) != -1) {
    xasprintf(&path, "/proc/%lld/cwd", (long long) sid);
    n = readlink(path, target, MAXPATHLEN);
    free(path);
    }
    if (n > 0) {
    target[n] = '\0';
    return (target);
    }
    return (NULL);
    }

    So, basically the same as /proc/$$/cwd.

    Any ideas how to access the $PWD of the running process from the tmux command line?

  4. nicm commented on Mar 15, 2018

    @nicm
    Member

    You will need to make the shell tell tmux by setting something in the tmux environment or a user option.

  5. sorsasampo commented on Mar 15, 2018

    @sorsasampo
    Author

    And how would I do that exactly?

  6. nicm commented on Mar 15, 2018

    @nicm
    Member

    User option would probably be best, tmux set-option. You can use TMUX_PANE inside the pane to generate a unique name when you store the PWD, then use display -F #{pane_id} to get the current pane ID in a script, look up the option and pass it to neww -c.

  7. typelogic commented on Nov 27, 2019

    @typelogic

    Is there a fix to this? For bind-key c new-window -c "#{pane_current_path}" to work? I have 2.6 under cygwin.

  8. hanxi commented on Nov 27, 2019

    @hanxi

    @typelogic I use symlinked like this:

    # .bashrc
    # set pwd for tmux
    function set_tmux_pwd() {
        [ -n "$TMUX" ] && tmux setenv TMUXPWD_$(tmux display -p "#D" | tr -d %) "$PWD"
        return 0
    }
    function my_cd() {
        \cd $1
        set_tmux_pwd
    }
    set_tmux_pwd
    alias cd=my_cd
    
    # .tmux.conf
    # this support symbolic link
    bind c run-shell 'tmux new-window "cd \"$(tmux show-environment $(echo "TMUXPWD_#D" | tr -d %) | sed -e "s/^.*=//")\"; exec $SHELL"'
    bind '"' run-shell 'tmux split-window -v "cd \"$(tmux show-environment $(echo "TMUXPWD_#D" | tr -d %) | sed -e "s/^.*=//")\"; exec $SHELL"'
    bind '%' run-shell 'tmux split-window -h "cd \"$(tmux show-environment $(echo "TMUXPWD_#D" | tr -d %) | sed -e "s/^.*=//")\"; exec $SHELL"'
    
  9. lock commented on Mar 11, 2020

    @lock

    This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

  10. locked and limited conversation to collaborators on Mar 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions