Created
September 7, 2014 11:31
-
-
Save ithompson/20b41ca274a9da47138a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Check whether there are child zsh processes to pull cwd from | |
# Sets $BEST_PID to the PID of the deepest zsh process | |
# | |
# Usage: checkchildren <PID> | |
function checkchildren() { | |
if [[ $# -eq 1 ]]; then | |
psdata=(`ps ho pid,comm --ppid=$1`) | |
if [[ ${#psdata[@]} -ge 2 ]]; then | |
if [[ "${psdata[1]}" == "zsh" ]]; then | |
BEST_PID=${psdata[0]} | |
fi | |
checkchildren ${psdata[0]} | |
fi | |
fi | |
} | |
if [[ $# -ne 1 ]]; then | |
echo "Usage: $0 <PID>" | |
exit | |
fi | |
ps $1 > /dev/null | |
if [[ $? -ne 0 ]]; then | |
echo "Process not found" | |
exit | |
fi | |
BEST_PID=$1 | |
checkchildren $1 | |
dir=`pwdx $BEST_PID | sed 's/.*: //'` | |
cd "$dir" | |
urxvt & |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment