Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

executable file 17 lines (14 sloc) 0.555 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
#!/bin/sh
# Runs the given command inside the working directory of
# the currently focused X11 window if possible. Otherwise,
# runs the given command in the present working directory.

xid=$(xdpyinfo | awk '/^focus:/{print $3; exit}' | tr -d ',') &&
pid=$(xprop -id "$xid" _NET_WM_PID | cut -d' ' -f3) &&
{
  # when current window is terminal, target its shell child
  cid=$(pgrep -P "$pid") && test -n "$cid" && pid=$cid

  # travel to current window's present working directory
  cwd=/proc/$pid/cwd
  test -L $cwd && cd "$(readlink $cwd)"
}

eval "$@"
Something went wrong with that request. Please try again.