Code Monkey home page Code Monkey logo

tmux-current-pane-hostname's Introduction

Tmux current pane hostname/user

Tmux plugin that enables displaying hostname and user of the current pane in your status bar.

Replaces the #H format and adds a #U format option.

Usage

  • #H will be the hostname of your current path. If there is an ssh session opened, the ssh hostname will show instead of the local one.
  • #{hostname_short} will be the short hostname of your current path (up to the first dot). If there is an ssh session opened, the ssh hostname will show instead of the local one.
  • #U will show the whoami result or the user that logged in an ssh session.
  • #{pane_ssh_port} if an open ssh session will show the connection port, otherwise it will be empty.
  • #{pane_ssh_connected} will be set to 1 if the currently selected pane has an active ssh connection. (Useful for #{?#{pane_ssh_connected},ssh,no-ssh} which will evaluate to ssh if there is an active ssh in the currently selected pane and no-ssh otherwise.)

Here's the example in .tmux.conf:

set -g status-right '#[fg=cyan,bold] #U@#H #[default]#[fg=blue]#(tmux display-message -p "#{pane_current_path}" | sed "s#$HOME#~#g") #[fg=red]%H:%M %d-%b-%y#[default]'

Installation with Tmux Plugin Manager (recommended)

Add plugin to the list of TPM plugins in .tmux.conf:

set -g @tpm_plugins "                 \
  tmux-plugins/tpm                    \
  soyuka/tmux-current-pane-hostname     \
"

Hit prefix + I to fetch the plugin and source it.

#U@#H interpolation should now take the current pane ssh status into consideration.

Manual Installation

Clone the repo:

$ git clone https://github.com/soyuka/tmux-current-pane-hostname ~/clone/path

Add this line to the bottom of .tmux.conf:

run-shell ~/clone/path/current_pane_hostname.tmux

Reload TMUX environment:

# type this in terminal
$ tmux source-file ~/.tmux.conf

#U@#H interpolation should now work.

Limitations

I wanted to get the current path of the opened ssh session but that's not possible. I haven't found a way to get the output of a remote command that will be executed on an opened ssh session. A dirty way would be to use send-keys pwd Enter but this will show on the pane and we don't want this. So, I'm just getting the correct ssh command corresponding to the pane job pid and parsing it, for example:

ssh [email protected]
# #H => host.com
# #U => test

License

MIT

tmux-current-pane-hostname's People

Contributors

soyuka avatar cybolic avatar mathieu-lemay avatar skrip42 avatar b4nst avatar mitchellvitez avatar townk avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.