Make terminal open in the directory of active directory

Jonathan Hodgson 7 years ago
parent 7d53123d6d
commit 9735245bfb
  1. 29
      bin/i3-shell
  2. 3
      i3/configWork
  3. 6
      shells/functions
  4. 6
      shells/zsh/zshrc

@ -0,0 +1,29 @@
#!/bin/bash
# i3 thread: https://faq.i3wm.org/question/150/how-to-launch-a-terminal-from-here/?answer=152#post-id-152
# I stole this from here: https://gist.github.com/viking/5851049
CMD=$TERMINAL
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
TREE=$(pstree -lpA $PID | tail -n 1)
PID=$(echo $TREE | awk -F'---' '{print $NF}' | sed -re 's/[^0-9]//g')
# If we find the working directory, run the command in that directory
if [ -e "/proc/$PID/cwd" ]; then
CWD=$(readlink /proc/$PID/cwd)
fi
fi
if [ -n "$CWD" ]; then
cd $CWD && $CMD
else
$CMD
fi

@ -45,7 +45,8 @@ floating_modifier $mod
# bindsym $mod+Return exec xfce4-terminal # bindsym $mod+Return exec xfce4-terminal
# bindsym $mod+Return exec konsole # bindsym $mod+Return exec konsole
# bindsym $mod+Return exec termite # bindsym $mod+Return exec termite
bindsym $mod+Return exec /usr/local/bin/st # bindsym $mod+Return exec /usr/local/bin/st
bindsym $mod+Return exec ~/.dotfiles/bin/i3-shell
# kill focused window # kill focused window
bindsym $mod+q kill bindsym $mod+q kill

@ -38,9 +38,9 @@ function mycd() {
cd "$@" 2> /dev/null cd "$@" 2> /dev/null
if [ $? = 0 ]; then if [ $? = 0 ]; then
# If we get here cd was successful # If we get here cd was successful
if [ ! $TMUX ]; then #if [ ! $TMUX ]; then
pwd > ~/.current-folder # pwd > ~/.current-folder
fi #fi
ls ls
else else
# If we get here, cd was not successful # If we get here, cd was not successful

@ -91,6 +91,6 @@ TRAPWINCH(){
zle && {zle reset-prompt; zle -R} zle && {zle reset-prompt; zle -R}
} }
if [ -f ~/.current-folder ] && [ ! $TMUX ]; then #if [ -f ~/.current-folder ] && [ ! $TMUX ]; then
\cd "$(cat ~/.current-folder)" # \cd "$(cat ~/.current-folder)"
fi #fi

Loading…
Cancel
Save