Skip to content

Instantly share code, notes, and snippets.

@ozh
Created May 6, 2026 19:42
Show Gist options
  • Select an option

  • Save ozh/e39553870013312b197e1e8c1f623c94 to your computer and use it in GitHub Desktop.

Select an option

Save ozh/e39553870013312b197e1e8c1f623c94 to your computer and use it in GitHub Desktop.
`cdhere` : `cd` to wherever the last active Nemo window was

In your .bashrc or alias/functions definitions:

cdhere() {
    # Get all Nemo window IDs
    nemo_ids=$(xdotool search --classname nemo)

    # Get stacking order (last = most recently focused)
    stacking=$(xprop -root _NET_CLIENT_LIST_STACKING \
     | grep -oP '0x[0-9a-f]+' \
     | xargs -I{} printf "%d\n" {})

    # Find the Nemo window highest in the stack
    last_nemo=""
    while read -r wid; do
       if echo "$nemo_ids" | grep -qx "$wid"; then
           last_nemo="$wid"
       fi
    done <<< "$stacking"

    if [[ -n "$last_nemo" ]]; then
        title=$(xdotool getwindowname "$last_nemo")
        if [[ "$title" == "Home" ]]; then
            cd ~
        else
            path="${title##* - }"
            cd "$path"
        fi
    fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment