-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtermFromHere.spell
More file actions
executable file
·34 lines (29 loc) · 879 Bytes
/
Copy pathtermFromHere.spell
File metadata and controls
executable file
·34 lines (29 loc) · 879 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/bin/bash
# Opens a terminal in the same `cwd` as the focused `X` program.
# depends: xorg-xdpyinfo xorg-xprop
CWD=''
# Get window ID
ID=$(xdpyinfo | grep focus | cut -f4 -d " ")
# Get PID of process whose window this is
PID=$(xprop -id "$ID" | grep -m 1 PID | cut -d " " -f 3)
# Get last child process (shell, vim, etc)
if [ -n "$PID" ]; then
CPID=$(pstree -lpA "$PID" \
| grep -oP '(bash|zsh|vim|nvim)\([0-9]+\)' \
| tail -1 \
| grep -oP '[0-9]+')
# If we find the working directory, run the command in that directory
if [ -e "/proc/$CPID/cwd" ]; then
CWD=$(readlink /proc/"$CPID"/cwd)
fi
fi
if [ -n "$CWD" ]; then
cd "$CWD" || exit 1
$TERMINAL "$@" &
else
notify-send -u low "Couldn't find cwd" -a "$(basename "$0")" -t 1000
$TERMINAL "$@" &
fi
xdotool search --pid $! --onlyvisible --sync >/dev/null
disown
exit