mybin

my ~/bin
git clone https://a3nm.net/git/mybin/
Log | Files | Refs | README

commit 088c0161a2b71f57e3df2b2800fed3f0d8e82109
parent 7294fe669e585a8eb77c8dece81466a484d97269
Author: Antoine Amarilli <a3nm@a3nm.net>
Date:   Wed, 21 Dec 2016 11:42:13 +0100

filter on class

Diffstat:
urxvtpwd | 27+++++++++++++++++----------
1 file changed, 17 insertions(+), 10 deletions(-)

diff --git a/urxvtpwd b/urxvtpwd @@ -3,24 +3,31 @@ # run ARGV, with -cd FOLDER if FOLDER can be extracted from title of current # window (see zsh config for how the title gets put in the window) +# http://superuser.com/a/403369/77814 +quoted_args="$(printf " %q" "$@")" + # inspired by # https://faq.i3wm.org/question/150/how-to-launch-a-terminal-from-here/%3C/p%3E.html - ID=$(xdpyinfo | grep focus | cut -d ',' -f1 | rev | cut -d ' ' -f1 | rev) +CLASS=$(xprop -id "$ID" | grep -m1 WM_CLASS | cut -d'"' -f2) + +# http://stackoverflow.com/a/19411918 +if [ "${CLASS^^}" != "URXVT" ] +then + # no urxvt focused -- just do the default + # optionally we could try to extract the pwd with + # https://github.com/schischi-a/xcwd or something + exec $quoted_args +fi + TITLE=$(xprop -id "$ID" | grep -m1 WM_NAME) MYPWD=$(echo "$TITLE" | cut -d'$' -f1 | cut -d'"' -f2- | cut -d':' -f2-) MYPWD2="${MYPWD/#\~/$HOME}" -echo $MYPWD2 > ~/scratch/pwd - -# http://superuser.com/a/403369/77814 -quoted_args="$(printf " %q" "$@")" - -if [ -z "$MYPWD2" ] +if [ -z "$MYPWD2" -a -d "$MYPWD2" -a -r "$MYPWD2" -a -x "$MYPWD2" ] then - $quoted_args + exec $quoted_args else - echo "$quoted_args -cd $MYPWD2" > ~/scratch/pwd - $quoted_args -cd "$MYPWD2" + exec $quoted_args -cd "$MYPWD2" fi