mirror of
https://github.com/FAUSheppy/config
synced 2025-12-06 07:01:36 +01:00
added cwd open urxvt
This commit is contained in:
@@ -48,7 +48,7 @@ hc keybind $Mod-q close
|
|||||||
|
|
||||||
#spawn shit
|
#spawn shit
|
||||||
hc keybind $Mod-Return spawn urxvt
|
hc keybind $Mod-Return spawn urxvt
|
||||||
hc keybind $Mod-Shift-Return spawn xterm /bin/bash
|
hc keybind $Mod-Shift-Return spawn ~/.config/herbstluftwm/cwd_helper.py
|
||||||
hc keybind $Mod-i spawn urxvt -e nohup zsh -c "chromium &" #need to reliably use the zshconf chromium
|
hc keybind $Mod-i spawn urxvt -e nohup zsh -c "chromium &" #need to reliably use the zshconf chromium
|
||||||
if [[ $HOST =~ atlantis* ]]; then
|
if [[ $HOST =~ atlantis* ]]; then
|
||||||
hc keybind $Mod-l spawn i3lock -i ~/.config/i3lock/bg.png -t
|
hc keybind $Mod-l spawn i3lock -i ~/.config/i3lock/bg.png -t
|
||||||
|
|||||||
50
herbstluftwm/cwd_helper.py
Executable file
50
herbstluftwm/cwd_helper.py
Executable file
@@ -0,0 +1,50 @@
|
|||||||
|
#!/usr/bin/python3
|
||||||
|
|
||||||
|
import subprocess
|
||||||
|
import datetime
|
||||||
|
import sys
|
||||||
|
import os
|
||||||
|
import shlex
|
||||||
|
import psutil
|
||||||
|
|
||||||
|
def error(s):
|
||||||
|
with open("herbstlog",'a') as f:
|
||||||
|
time = str(datetime.datetime.now().time())[:-7] #cut seconds at the end
|
||||||
|
f.write(time + "ERROR" + os.path.basename(__file__) + s)
|
||||||
|
|
||||||
|
out = subprocess.check_output(['xdpyinfo']).decode().split('\n')
|
||||||
|
|
||||||
|
############ GET FOCUSED WINDOW ID ##############
|
||||||
|
window = -1
|
||||||
|
for l in out:
|
||||||
|
if l.startswith('focus:'):
|
||||||
|
for field in l.split(' '):
|
||||||
|
field = field.rstrip(',')
|
||||||
|
if(field.startswith('0x')):
|
||||||
|
window = int(field,16)
|
||||||
|
if window == -1:
|
||||||
|
error("Failed to get window_focus\n")
|
||||||
|
if window==-1:
|
||||||
|
sys.exit()
|
||||||
|
|
||||||
|
############ IF URXVT GET PID ###########
|
||||||
|
pid = -1
|
||||||
|
out = subprocess.check_output(shlex.split('xprop -id '+hex(window))).decode().split('\n')
|
||||||
|
for l in out:
|
||||||
|
if l.startswith('WM_CLASS(STRING)') and 'urxvt' in l:
|
||||||
|
break;
|
||||||
|
else:
|
||||||
|
sys.exit();
|
||||||
|
|
||||||
|
for l in out:
|
||||||
|
if l.startswith('_NET_WM_PID(CARDINAL)'):
|
||||||
|
pid = int(l.split(' ')[-1])
|
||||||
|
if pid==-1:
|
||||||
|
error("Failed to get PID")
|
||||||
|
|
||||||
|
process = psutil.Process(pid)
|
||||||
|
for p in process.children(): #recursive=false
|
||||||
|
if p.name()=='zsh' or p.name()=='bash':
|
||||||
|
subprocess.Popen(shlex.split('urxvt -cd ' + p.cwd()))
|
||||||
|
break
|
||||||
|
sys.exit()
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
ID=$(xdpyinfo | grep focus | cut -f4 -d " ")
|
|
||||||
PID=$(($(xprop -id $ID | grep -m 1 PID | cut -d " " -f 3) + 2))
|
|
||||||
if [ -e "/proc/$PID/cwd" ]
|
|
||||||
then
|
|
||||||
urxvt -cd $(readlink /proc/$PID/cwd) &
|
|
||||||
else
|
|
||||||
urxvt
|
|
||||||
fi
|
|
||||||
|
|
||||||
Reference in New Issue
Block a user