Skip to content

Instantly share code, notes, and snippets.

@vilhalmer
Last active December 15, 2018 17:47
Show Gist options
  • Save vilhalmer/bd096cc30193158994ea8d7ad5720c77 to your computer and use it in GitHub Desktop.
Save vilhalmer/bd096cc30193158994ea8d7ad5720c77 to your computer and use it in GitHub Desktop.
Open new terminals in the directory of the currently focused one, if any
#!/usr/bin/env bash
pid=$(cat /proc/*/stat 2>/dev/null | awk '{if ($4 == focused_pid) { print $1 }}' focused_pid="$(swaymsg -t get_tree | jq 'recurse(.nodes[]?) | select(.focused).pid')")
directory=$(readlink "/proc/$pid/cwd")
swaymsg "exec 'cd $directory; exec \$term'"
@vilhalmer
Copy link
Author

Bind this to your terminal key in sway instead of $term, but leave $term set as usual. Like so:

set $term termite
bindsym $mod+Return exec $HOME/scripts/cwd-terminal

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment