aboutsummaryrefslogtreecommitdiff
path: root/.scripts
diff options
context:
space:
mode:
authorMikunoNaka <bokuwakanojogahoshii@yahoo.com>2021-08-26 20:03:19 +0530
committerMikunoNaka <bokuwakanojogahoshii@yahoo.com>2021-08-26 20:03:19 +0530
commitcf30deb40455c090bb7e7ed5d5433f8951dc4a6e (patch)
tree1dfcfbe3e9fb0e70a77ecaf221ab921ce43460d9 /.scripts
parentff7dcaef8f46b83585ffb706744e5c2bff3df829 (diff)
Added script to open alacritty in same directory, and set its keybinding
Diffstat (limited to '.scripts')
-rwxr-xr-x.scripts/open_terminal27
1 files changed, 27 insertions, 0 deletions
diff --git a/.scripts/open_terminal b/.scripts/open_terminal
new file mode 100755
index 0000000..62ac7cc
--- /dev/null
+++ b/.scripts/open_terminal
@@ -0,0 +1,27 @@
+#!/bin/sh
+
+ACTIVE_WINDOW=$(xdotool getactivewindow)
+ACTIVE_WM_CLASS=$(xprop -id $ACTIVE_WINDOW | grep WM_CLASS)
+if [[ $ACTIVE_WM_CLASS == *"Alacritty"* ]]
+then
+ # Get PID. If _NET_WM_PID isn't set, bail.
+ PID=$(xprop -id $ACTIVE_WINDOW | grep _NET_WM_PID | grep -oP "\d+")
+ if [[ "$PID" == "" ]]
+ then
+ alacritty
+ fi
+ # Get first child of terminal
+ CHILD_PID=$(pgrep -P $PID)
+ if [[ "$PID" == "" ]]
+ then
+ alacritty
+ fi
+ # Get current directory of child. The first child should be the shell.
+ pushd "/proc/${CHILD_PID}/cwd"
+ SHELL_CWD=$(pwd -P)
+ popd
+ # Start alacritty with the working directory
+ alacritty --working-directory $SHELL_CWD
+else
+ alacritty
+fi