shosei

tmux-split-cwd.sh

Mar 12th, 2012
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.63 KB | None | 0 0
  1. #!/bin/sh
  2. # tmux-split-in-cwd - open a new shell with same cwd as calling pane
  3.  
  4. SIP=$(tmux display-message -p "#S:#I:#P")
  5. PTY=$(tmux server-info |
  6.         egrep flags=\|bytes |
  7.         awk '/windows/ { s = $2 }
  8.             /references/ { i = $1 }
  9.             /bytes/ { print s i $1 $2 } ' |
  10.         grep "$SIP" |
  11.         cut -d: -f4)
  12. PTS=${PTY#/dev/}
  13. PID=$(ps -eao pid,tty,command --forest | awk '$2 == "'$PTS'" {print $1; exit}')
  14. DIR=$(readlink /proc/$PID/cwd)
  15.  
  16. case "$1" in
  17.   h) tmux splitw -h "cd '$DIR'; $SHELL"
  18.      ;;
  19.   v) tmux splitw -v "cd '$DIR'; $SHELL"
  20.      ;;
  21.   *) tmux neww "cd '$DIR'; $SHELL"
  22.      ;;
  23. esac
Advertisement
Add Comment
Please, Sign In to add comment