Re: Open Terminal in Current Directory

Jean Louis <[email protected]>
Newsgroups gmane.emacs.help
Organization GNU Support
Message-ID <[email protected]>
On 2026-04-12 22:44, Philip Kaludercic wrote:
> I am going through my init.el and found this function
> 
> --8<---------------cut here---------------start------------->8---
> (defun site/open-xterm ()
>   "Start an Xterm process."
>   (interactive)
>   (let ((term (cond ((executable-find "gnome-terminal")
>                      "gnome-terminal")
>                     ((executable-find "xterm")
>                      "xterm")
>                     ((error "Couldn't find a terminal emulator")))))
>     (start-process "*xterm*" nil term)))
> --8<---------------cut here---------------end--------------->8---
> 
> Does anyone have a more portable solution, where I don't have to list
> all possible kinds of terminal emulators?

(defun site/open-terminal ()
   "Launch a terminal emulator using an exhaustively overkill detection 
method.

This function attempts to find ANY terminal emulator ever conceived by
humanity, from the most obscure suckless tool to enterprise-grade GPU-
accelerated Rust-powered terminals you've never heard of.

The detection list includes:
- 50+ terminal emulators spanning 4 decades of computing history
- Desktop environment defaults (GNOME, KDE, XFCE, MATE, Cinnamon, 
Budgie, etc.)
- Modern GPU-accelerated terminals (Alacritty, Kitty, Wezterm, Rio, 
Ghostty)
- Drop-down terminals (Guake, Tilda, Yakuake)
- Lightweight terminals (st, urxvt, termite, Sakura)
- Terminal multiplexers masquerading as terminals (tmux, screen, zellij)
- Flatpak and Snap variants with their reverse-DNS naming conventions
- Windows terminals (WT, WSL Terminal, Mintty, CMD, PowerShell)
- macOS Terminal.app via open command
- Legacy terminals (xterm, rxvt, kterm, aterm)
- Electron-based monsters (Hyper, Tabby, Extraterm)
- That one terminal your weird cousin wrote in Rust last week

If it finds one, it launches it. If it doesn't, it admits defeat
because clearly you're running on something that isn't a computer.

Returns nothing on success. Signals an error if no terminal emulator
could be found (unlikely, unless you're using a toaster)."
   (interactive)
   (let ((terminal-list
          '(
            ;; Debian/Ubuntu standard
            "x-terminal-emulator"

            ;; Desktop environment defaults
            "gnome-terminal" "gnome-terminal.wrapper" 
"gnome-terminal.real"
            "konsole" "kde-terminal"
            "xfce4-terminal" "xfce-terminal"
            "mate-terminal"
            "lxterminal" "lxde-terminal"
            "cinnamon-terminal"
            "pantheon-terminal" "io.elementary.terminal"
            "deepin-terminal"
            "budgie-terminal"
            "tilix"
            "terminology"

            ;; Modern GPU-accelerated terminals
            "alacritty" "alacritty.exe"
            "kitty"
            "wezterm" "wezterm-gui"
            "rio"
            "ghostty"
            "contour"
            "extraterm"

            ;; Drop-down terminals
            "guake"
            "tilda"
            "yakuake"

            ;; Terminal multiplexers (close enough)
            "terminator"
            "tmux"
            "screen"
            "zellij"

            ;; Tiling window manager defaults
            "i3-sensible-terminal"
            "suckless-tools"

            ;; Lightweight
            "st" "simple-terminal"
            "termite"
            "urxvt" "urxvtc" "rxvt" "rxvt-unicode"
            "mlterm"
            "sakura"
            "roxterm"
            "eterm"
            "aterm"
            "mrxvt"
            "wterm"
            "terminal"

            ;; Old school classics
            "xterm" "uxterm" "nxterm" "xterm-color"
            "kterm"

            ;; macOS
            "Terminal"

            ;; Windows/WSL abominations
            "wt" "windows-terminal"
            "wsl-terminal" "wslg-terminal"
            "mintty"
            "cmd.exe" "powershell.exe" "pwsh.exe"

            ;; Flatpak nonsense
            "org.gnome.Terminal"
            "org.kde.konsole"
            "io.alacritty.Alacritty"
            "com.wezfurlong.wezterm"
            "com.termius.Termius"

            ;; AppImage
            "AppRun"
            )))
     (let ((term (cl-find-if #'executable-find terminal-list)))
       (cond
        ((and (eq system-type 'darwin)
              (or (null term) (string= term "Terminal")))
         (start-process "*terminal*" nil "open" "-a" "Terminal")
         (message "Opened Terminal.app (macOS fallback)"))

        ((and (eq system-type 'windows-nt)
              (or (string= term "wt") (null term)))
         (start-process "*terminal*" nil "wt")
         (message "Opened Windows Terminal (Windows fallback)"))

        (term
         (start-process "*terminal*" nil term)
         (message "Opened terminal: %s" term))

        (t
         (error "No terminal emulator found. Did you install one? On a 
COMPUTER?"))))))

-- 
Jean Louis
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.