Skip to content

Instantly share code, notes, and snippets.

@enpinzolas
Last active April 23, 2026 19:29
Show Gist options
  • Select an option

  • Save enpinzolas/7a32ca2765a69f4d96e81eef711f78bc to your computer and use it in GitHub Desktop.

Select an option

Save enpinzolas/7a32ca2765a69f4d96e81eef711f78bc to your computer and use it in GitHub Desktop.

Revisions

  1. enpinzolas revised this gist Apr 23, 2026. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -4,7 +4,7 @@ This should work with most terminals, as long as they allow for custom titles or
    using them only in dropdown mode.

    The idea is to create a down rule that forces the window to stay in the position you want,
    and to create a script using kdotool to execute the terminal if it's not running, and minimize/show it if it's running. The current tool is a slightly altered version of @despian's improved version due to personal preference.
    and to create a script using kdotool to execute the terminal if it's not running, and minimize/show it if it's running. The current script is a slightly altered version of @despian's improved version due to personal preference.

    This should also work in x11 with minimal changes. I personally like for the terminal to stay on top always,
    and for the keybind to hide/show it, regardless of my current focus since I work with two monitors and the first press gaining
  2. enpinzolas revised this gist Apr 23, 2026. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -4,7 +4,7 @@ This should work with most terminals, as long as they allow for custom titles or
    using them only in dropdown mode.

    The idea is to create a down rule that forces the window to stay in the position you want,
    and to create a script using kdotool to execute the terminal if it's not running, and minimize/show it if it's running.
    and to create a script using kdotool to execute the terminal if it's not running, and minimize/show it if it's running. The current tool is a slightly altered version of @despian's improved version due to personal preference.

    This should also work in x11 with minimal changes. I personally like for the terminal to stay on top always,
    and for the keybind to hide/show it, regardless of my current focus since I work with two monitors and the first press gaining
  3. enpinzolas revised this gist Apr 23, 2026. 1 changed file with 37 additions and 13 deletions.
    50 changes: 37 additions & 13 deletions alacritty_drop.zsh
    Original file line number Diff line number Diff line change
    @@ -1,27 +1,51 @@
    #!/usr/bin/env bash

    name_window_search="AlacrittyDrop"
    active_flag_file="$0.flag" # Sadly we need to use a flag file to track the window status
    window_title="AlacrittyDrop"

    window_is_minimized() {
    local target="$1"
    [[ -z "$target" ]] && return 1
    kdotool windowstate --is MINIMIZED "$target" >/dev/null 2>&1
    }

    launch_alacritty() {
    # setsid --fork detaches cleanly so the script can exit immediately
    setsid -f alacritty --config-file $HOME/.config/alacritty/alacritty_drop.toml -T $window_title >/dev/null 2>&1

    local wid=""
    # Wait briefly for the new window so we can ensure full width (window rule seemed unreliable here)
    for _ in {1..40}; do
    wid=$(kdotool search --name "$window_title" 2>/dev/null | head -n1)
    if [[ -n "$wid" ]]; then
    kdotool windowsize "$wid" 100% y >/dev/null 2>&1
    break
    fi
    sleep 0.05
    done
    }

    toggle() {
    window_id=$(kdotool search --name "${name_window_search}")
    window_id=$(kdotool search --name "${window_title}" 2>/dev/null | head -n1)
    focused_window=$(kdotool getactivewindow 2>/dev/null | head -n1)
    echo $window_id

    case "${window_id}" in
    "")
    # Window not found, running. Using custom config to disable borders. Check alacritty config docs https://alacritty.org/config-alacritty.html
    dbus-launch alacritty --config-file $HOME/.config/alacritty/alacritty_drop.toml -T $name_window_search
    touch $active_flag_file
    # Window not found, launch.
    launch_alacritty
    ;;
    *)
    # I did try using "windowstate --toggle MINIMIZED $window_id" but it doesn't focus the window on maximize
    if [ -f $active_flag_file ]; then
    # Window active, minimize
    kdotool windowminimize "${window_id}"
    rm $active_flag_file
    else
    if window_is_minimized "${window_id}"; then
    # Window minimized, show and focus
    kdotool windowactivate "${window_id}"
    touch $active_flag_file
    else
    if [[ -n "${focused_window}" && "${window_id}" == "${focused_window}" ]]; then
    # Window active and focused, minimize
    kdotool windowminimize "${window_id}"
    else
    # Window active but unfocused, just focus it
    kdotool windowactivate "${window_id}"
    fi
    fi
    ;;
    esac
  4. enpinzolas revised this gist May 16, 2025. 2 changed files with 4 additions and 1 deletion.
    3 changes: 3 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,8 @@
    This idea is absed on the following snippet for wezterm: https://gitlab.com/-/snippets/4798512

    This should work with most terminals, as long as they allow for custom titles or if you don't mind
    using them only in dropdown mode.

    The idea is to create a down rule that forces the window to stay in the position you want,
    and to create a script using kdotool to execute the terminal if it's not running, and minimize/show it if it's running.

    2 changes: 1 addition & 1 deletion alacritty_drop.zsh
    Original file line number Diff line number Diff line change
    @@ -8,7 +8,7 @@ toggle() {

    case "${window_id}" in
    "")
    # Window not found, running.
    # Window not found, running. Using custom config to disable borders. Check alacritty config docs https://alacritty.org/config-alacritty.html
    dbus-launch alacritty --config-file $HOME/.config/alacritty/alacritty_drop.toml -T $name_window_search
    touch $active_flag_file
    ;;
  5. enpinzolas created this gist May 16, 2025.
    38 changes: 38 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,38 @@
    This idea is absed on the following snippet for wezterm: https://gitlab.com/-/snippets/4798512

    The idea is to create a down rule that forces the window to stay in the position you want,
    and to create a script using kdotool to execute the terminal if it's not running, and minimize/show it if it's running.

    This should also work in x11 with minimal changes. I personally like for the terminal to stay on top always,
    and for the keybind to hide/show it, regardless of my current focus since I work with two monitors and the first press gaining
    focus when I want to hide it is annoying. In any case, here is the script excerpt in case the snippet link is deleted and that
    interaction is preferred, this should also work with xdotool:

    ```bash
    toggle() {
    WINDOW_ID=$(kdotool search --name "${NAME_WINDOW_SEARCH}")
    ACTIVE_ID=$(kdotool getactivewindow)

    case "${WINDOW_ID}" in
    "")
    dbus-launch ${TERMINAL_BIN} ${ADDITIONAL_ARGS}
    ;;
    "${ACTIVE_ID}")
    echo "Focused->Hidden"
    kdotool windowminimize "${WINDOW_ID}"
    ;;
    *)
    echo "Hidden/Unfocused->Focused"
    kdotool windowactivate "${WINDOW_ID}"
    ;;
    esac
    }
    ```

    We will create several window rules to enforce the positioning of the terminal, ths can be changed to the preference of the
    user. The only important part is where we define the window title, it must be the same as the one defined in the script.
    ![image](https://gist.github.com/user-attachments/assets/11da7985-f610-4e1c-ba8a-13d244a5f1a2)

    Now we only need a keybind that launches the script and it will work. Remember making the script executable too.
    ![image](https://gist.github.com/user-attachments/assets/b83c4d78-55e5-4e78-98dd-b74559a20abd)

    30 changes: 30 additions & 0 deletions alacritty_drop.zsh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,30 @@
    #!/usr/bin/env bash

    name_window_search="AlacrittyDrop"
    active_flag_file="$0.flag" # Sadly we need to use a flag file to track the window status

    toggle() {
    window_id=$(kdotool search --name "${name_window_search}")

    case "${window_id}" in
    "")
    # Window not found, running.
    dbus-launch alacritty --config-file $HOME/.config/alacritty/alacritty_drop.toml -T $name_window_search
    touch $active_flag_file
    ;;
    *)
    # I did try using "windowstate --toggle MINIMIZED $window_id" but it doesn't focus the window on maximize
    if [ -f $active_flag_file ]; then
    # Window active, minimize
    kdotool windowminimize "${window_id}"
    rm $active_flag_file
    else
    # Window minimized, show and focus
    kdotool windowactivate "${window_id}"
    touch $active_flag_file
    fi
    ;;
    esac
    }

    toggle