2

Tmux has an option to have the #{pane_current_path} as a name for the current pane in the status line. This is great but has two short falls for me:

  1. $HOME is not displayed as ~.
  2. I only really need the last directory name, not the full path from /. So, for example /home/ook/thingy/src would only be displayed as either src or ~/t/src.

Is there a Tmux command that does this?

Bonus points if it works with powerline as well.

1

I tried to find something similar recently, in my case, for setting the window information (for the Tmux command choose-window) to something more informative than the default.

In the man page, the relevant information seems to be in the FORMATS section, which is also used by the status-{left,right} commands:

FORMATS

Certain commands accept the -F flag with a format argument. This is a string which controls the output format of the command. Replacement variables are enclosed in ‘#{’ and ‘}’, for example ‘#{session_name}’. The possible variables are listed in the table below, or the name of a tmux option may be used for an option's value. Some variables have a shorter alias such as ‘#S’, and ‘##’ is replaced by a single ‘#’.

Conditionals are available by prefixing with ‘?’ and separating two alternatives with a comma; if the specified variable exists and is not zero, the first alternative is chosen, otherwise the second is used. For example ‘#{?session_attached,attached,not attached}’ will include the string ‘attached’ if the session is attached and the string ‘not attached’ if it is unattached, or ‘#{?automatic-rename,yes,no}’ will include ‘yes’ if automatic-rename is enabled, or ‘no’ if not.

A limit may be placed on the length of the resultant string by prefixing it by an ‘=’, a number and a colon. Positive numbers count from the start of the string and negative from the end, so ‘#{=5:pane_title}’ will include at most the first 5 characters of the pane title, or ‘#{=-5:pane_title}’ the last 5 characters. Prefixing a time variable with ‘t:’ will convert it to a string, so if ‘#{window_activity}’ gives ‘1445765102’, ‘#{t:window_activity}’ gives ‘Sun Oct 25 09:25:02 2015’. The ‘b:’ and ‘d:’ prefixes are basename(3) and dirname(3) of the variable respectively. A prefix of the form ‘s/foo/bar/:’ will substitute ‘foo’ with ‘bar’ throughout.

In addition, the first line of a shell command's output may be inserted using ‘#()’. For example, ‘#(uptime)’ will insert the system's uptime. When constructing formats, tmux does not wait for ‘#()’ commands to finish; instead, the previous result from running the same command is used, or a placeholder if the command has not been run before. Commands are executed with the tmux global environment set (see the ENVIRONMENT section).

After some attempts, I can't seem to make the built-in sed-like method work with the #{pane_current_path} directory name. Since you can also use any shell command or environmental variables, though, you can simply use some variation of

set status-left "#(basename ${PWD})"

I don't know about Powerline compatibility, since at the moment I'm not using it.

  • I cannot get this to work... Ah well, thank you nonetheless. – Sardathrion Feb 16 '16 at 8:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.