From 3480b7fa46be8c928a324c4e7e99edbb90e371af Mon Sep 17 00:00:00 2001 From: Julian Prein Date: Thu, 22 Dec 2022 11:07:23 +0100 Subject: [PATCH] bin: Add shcwd to get CWD of all running SHELLs This script is meant to be used in the future in an interactive fzf window bound to a key, so that one can quickly cd into the CWD of another running shell. --- .local/bin/shcwd | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100755 .local/bin/shcwd diff --git a/.local/bin/shcwd b/.local/bin/shcwd new file mode 100755 index 0000000..7f6becc --- /dev/null +++ b/.local/bin/shcwd @@ -0,0 +1,21 @@ +#!/bin/sh +# Get the current working directories of all running SHELLs. + +# The `pgrep` line can be replaced with following code block (resulting in two +# while-loops) if only child processes of certain programs (e.g. terminal and +# tmux instances) should be matched. +# +# pgrep --full "^($TERMINAL|tmux)( |$)" \ +# | cut -d' ' -f1 \ +# | while read -r line; do +# pgrep -P "$line" +# done \ + +# NOTE: when using the full path not all shell instances are matched +pgrep "$(basename $SHELL)" \ + | cut -d' ' -f1 \ + | while read -r line; do + pwdx "$line" 2>/dev/null + done \ + | cut -d' ' -f2- \ + | sort -u