Created
July 16, 2017 22:00
-
-
Save CD3/61ec20e7dd15ee64d4c3967a89ba2957 to your computer and use it in GitHub Desktop.
Small script that will open a new terminal in the working directory of the currently focused terminal. Useful with i3.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/bash | |
ID=$(xprop -root | gawk '/_NET_ACTIVE_WINDOW\(WINDOW\)/{print $NF}') | |
PID=$(xprop -id $ID | gawk '/_NET_WM_PID\(CARDINAL\)/{print $NF}') | |
SH=$(basename $SHELL) | |
ZPID=$(pstree -lpA $PID | sed -n "/$SH/ s/.*$SH(\([0-9]\+\)).*/\1/p") | |
if [[ -n $ZPID ]] | |
then | |
CWD=$(readlink /proc/$ZPID/cwd) | |
fi | |
if ! which $TERMINAL | |
then | |
TERMINAL=terminology | |
fi | |
if ! which $TERMINAL | |
then | |
TERMINAL=xterm | |
fi | |
if [[ -n $CWD ]] | |
then | |
cd $CWD && $TERMINAL | |
else | |
$TERMINAL | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I use this for my i3 terminal launch. Its useful for example if you are editing a script in vim and you want to open another terminal to run the script. This script will launch the terminal from the working directory of the vim terminal.