Make terminal open in the directory of active directory
This commit is contained in:
		
							parent
							
								
									d1ac6da0ba
								
							
						
					
					
						commit
						64e9ff9fa4
					
				
					 4 changed files with 37 additions and 7 deletions
				
			
		
							
								
								
									
										29
									
								
								bin/i3-shell
									
										
									
									
									
										Executable file
									
								
							
							
						
						
									
										29
									
								
								bin/i3-shell
									
										
									
									
									
										Executable file
									
								
							| 
						 | 
				
			
			@ -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 konsole
 | 
			
		||||
# 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
 | 
			
		||||
bindsym $mod+q kill
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -38,9 +38,9 @@ function mycd() {
 | 
			
		|||
	cd "$@" 2> /dev/null
 | 
			
		||||
	if [ $? = 0 ]; then
 | 
			
		||||
		# If we get here cd was successful
 | 
			
		||||
		if [ ! $TMUX ]; then
 | 
			
		||||
			pwd > ~/.current-folder
 | 
			
		||||
		fi
 | 
			
		||||
		#if [ ! $TMUX ]; then
 | 
			
		||||
		#	pwd > ~/.current-folder
 | 
			
		||||
		#fi
 | 
			
		||||
		ls
 | 
			
		||||
	else
 | 
			
		||||
		# If we get here, cd was not successful
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -91,6 +91,6 @@ TRAPWINCH(){
 | 
			
		|||
	zle && {zle reset-prompt; zle -R}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
if [ -f ~/.current-folder ] && [ ! $TMUX ]; then
 | 
			
		||||
	\cd "$(cat ~/.current-folder)"
 | 
			
		||||
fi
 | 
			
		||||
#if [ -f ~/.current-folder ] && [ ! $TMUX ]; then
 | 
			
		||||
#	\cd "$(cat ~/.current-folder)"
 | 
			
		||||
#fi
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue