[ home ]

Bash function: interactively go to working dir of other process

I don't use this anymore, but use these functions instead. They do everything this does.

Basically just as the title says. This uses dialog menu to pick from dirs, fetched from /proc/[0-9]*/cwd.

I use this to quickly go to the same dir where another shell/window is already sitting.


    function lcd() {

        local lst=()
        local IFS=$'\n' 

        for a in $( \
            readlink  -e /proc/[0-9]*/cwd  \
            |  sort                        \
            |  uniq                        \
            |  grep -v "^/$"               \
            |  grep -v "^$HOME$"           \
            |  grep -v "^$PWD$"            \
            ) 
        do
            lst+=($a)
            lst+=("")
        done

        case ${#lst[@]} in

            0)
                echo "(no other dir)"
                ;;

            2)
                pushd "${lst[0]}"  >/dev/null
                ;;

            *)
                dir=$( dialog  --keep-tite  --menu  "choose dir"  0 0 0  "${lst[@]}"  2>&1  >/dev/tty )

                if [ "$?" -eq 0 ]; then
                    pushd "$dir"  >/dev/null
                fi
                ;;

        esac
    }