Skip to content

Instantly share code, notes, and snippets.

@ctemplin
Created June 30, 2015 18:37
Show Gist options
  • Save ctemplin/3c626af969c67e51d805 to your computer and use it in GitHub Desktop.
Save ctemplin/3c626af969c67e51d805 to your computer and use it in GitHub Desktop.
Launch new xfce4-terminal starting in the working directory of the current xfce4-terminal or pwdx
#!/bin/bash
# Little script hack that launches a new xfce4-terminal with the
# current working directory as its default. Mimics pwdx with
# xfce4-terminal (all of whose windows share a single process for
# perfomance) by extracting the cwd from the window title. If the
# ACTIVE_WINDOW isn't a xfce4-terminal, use pwdx of the current
# window's PID.
id=$(xprop -root | awk '/_NET_ACTIVE_WINDOW\(WINDOW\)/{print $NF}')
class_string=$(xprop -id $id | awk '/WM_CLASS\(STRING\)/' | cut -d'=' -f2 | cut -d',' -f1)
if [ $class_string != '"xfce4-terminal"' ]
then
pid=$(xprop -id $id | awk '/_NET_WM_PID\(CARDINAL\)/' | cut -d'=' -f2)
cwd=$(pwdx $pid | cut -d':' -f2 | cut -d' ' -f2)
else
name=$(xprop -id $id | awk '/_NET_WM_NAME/' | cut -d'"' -f2 | cut -d" " -f4 );
name=$(echo "$name" | sed "s|~|$HOME|" )
cwd=$name
fi
cwd=${cwd:-$(echo $HOME)}
xfce4-terminal --default-working-directory $cwd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment