Coder Social home page Coder Social logo

davidshepherd7 / terminal-here Goto Github PK

View Code? Open in Web Editor NEW
70.0 4.0 12.0 126 KB

An Emacs package to open an external terminal emulator in the current directory

License: GNU General Public License v3.0

Emacs Lisp 98.11% Makefile 1.89%
emacs terminal-emulators

terminal-here's Introduction

Terminal Here

CI melpa melpa stable badge

An Emacs package to open an external terminal emulator in directories associated with the current buffer.

Usage

Quickstart

Run terminal-here-launch to start a terminal in the current directory.

Recommended keybindings:

(require 'terminal-here)
(global-set-key (kbd "C-<f5>") #'terminal-here-launch)
(global-set-key (kbd "C-<f6>") #'terminal-here-project-launch)

Configure the terminal

If the default command doesn't launch your preferred terminal you can configure it using these three variables:

  • terminal-here-linux-terminal-command
  • terminal-here-mac-terminal-command
  • terminal-here-windows-terminal-command

The documentation for these variables gives a list of terminals with builtin support. If your terminal is in the list simply set the variable for your OS to the terminal of your choice. e.g.

(setq terminal-here-linux-terminal-command 'urxvt)
(setq terminal-here-mac-terminal-command 'iterm2)

To use a terminal without builtin support, or to configure how your terminal is run, you can also set the variable to a list of strings specifying the command line which runs the terminal, e.g.

(setq terminal-here-linux-terminal-command '("urxvt" "-fade" "50"))

To support more even more complex terminals or selecting a terminal at runtime: you can set any of the *-terminal-command variables to a function which accepts a launch directory argument and returns a list of strings specifying the command line which runs the terminal.

To support other operating systems the variable terminal-here-terminal-command can be used instead of the OS-specific variables listed above. If set it will override other settings.

Remote directories

terminal-here can run ssh to open terminals in remote directories for files opened with tramp. For any of the predefined terminal configurations this should work without any configuration.

For other terminals you will need to set terminal-here-command-flag to the command line flag which tells the terminal to treat the rest of the command line as a separate command to run inside the terminal.

Inner commands

You can optionally provide a command to run inside the launched terminal as the argument to terminal-here-launch and terminal-here-project-launch.

Configuring these commands is pretty error prone and hard to debug, so below are some working examples to get you started. You might also find it useful to do (setq terminal-here-verbose t) to get some debugging information in the messages buffer.

Launch an interactive command and quit the terminal when it's done

(terminal-here-launch (list "htop"))

Launch an interactive command that acts on the current file

(terminal-here-launch (list "less" (buffer-file-name)))

Launch a non-interactive command and keep the terminal open when it's done

This runs ls and then drops you into your normal shell:

(terminal-here-launch (list (getenv "SHELL") "-c" "ls && exec $SHELL"))

Explanation: we start a non-interactive shell to run the command that we specify with -c. Inside this inner command we first run ls, then replace the non-interactive shell with a new interactive one.

Why do we need the non-interactive shell? Because we need the && syntax to run one command followed by another command, and that syntax requires a shell.

Why can't we just launch an interactive shell that runs a command first? Because unfortunately the common shells don't support that feature, I don't know why since it would be pretty handy!

Launch a shell with a python venv (HACK)

(terminal-here-launch (list (getenv "SHELL") "-c" "source .venv/bin/activate && exec $SHELL"))

Explanation: this is basically the same as the above except that the first command is sourcing a venv.

Strictly speaking this is not how venvs are intended to be used: really we should source the venv from inside the interactive shell. But this mostly works because the important part of a venv is setting some environment variables and the environment variables are inherited by the interactive shell.

Not everything works though, in particular the prompt is not modified to include the venv name. Other things may also break so if something else about your venv seems weird then try sourcing it manually instead.

Platforms

Terminal-here has out-of-the-box support for most platforms, but will work anywhere with some customisation.

Out-of-the-box support tested on:

  • Ubuntu (but should work identically on any Debian-based system)
  • Windows 10
  • OSX

Should be supported out-of-the-box, but currently untested:

  • Older versions of Windows
  • Non-Debian-based Linux systems with a desktop environment (e.g. GNOME, KDE)

Requires configuration before use:

  • Non-Debian-based UNIXes without a desktop environment (because there is no way to pick a good default terminal to use).

If you have problems just configure your terminal manually as described above.

Changelog

Unstable

  • Add support for running commands inside launched terminals.
  • Add the custom variable terminal-here-verbose to provide more debugging information.
  • Fix xfce terminal using the wrong name.
  • Add support for some additional terminals on Linux.
  • Add support for gnome-console (aka kgx)

2.0

  • Added support for simpler customisation by setting the terminal to a symbol from a list of supported terminal symbols.
  • Allow simple configuration of different terminals on different operating systems.
  • Improved selection of a default terminal for non-Debian Linux OSes.
  • Out-of-the-box support for SSH on many more terminals.

Alternatives

There are lots of built in ways to run terminals inside emacs (shell, eshell, ansi-term, ...) but these can have problems like slow output speed or incompatibility with existing configs. I currently prefer to run external terminal emulators, YMMV.

A couple of places on the internet have instructions for running specific terminals from Emacs, but they are not as portable as they could be.

terminal-here's People

Contributors

articuluxe avatar davidshepherd7 avatar jgarte avatar juergenhoetzel avatar mssdvd avatar purcell avatar romildo avatar syohex avatar wbolster avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

terminal-here's Issues

Rename or alias `terminal-here-launch`

I propose that you rename or alias terminal-here-launch to terminal-here

It's better for when calling it like M-x terminal-here

I can make a PR if you want, but first I want to know if you're ok with the idea ๐Ÿ˜‰

Add support for gnome-console

GNOME Console replaced gnome-terminal in the Arch Linux gnome package group.

Startup terminal-here fails

Debugger entered--Lisp error: (file-missing "Searching for program" "Datei oder Verzeichnis nicht gefunden" "gnome-terminal")
#<subr make-process>(:name "gnome-terminal" :buffer nil :command ("gnome-terminal"))
make-process--with-editor-process-filter(#<subr make-process> :name "gnome-terminal" :buffer nil :command ("gnome-terminal"))
apply(make-process--with-editor-process-filter #<subr make-process> (:name "gnome-terminal" :buffer nil :command ("gnome-terminal")))
make-process(:name "gnome-terminal" :buffer nil :command ("gnome-terminal"))
start-process("gnome-terminal" nil "gnome-terminal")
apply(start-process "gnome-terminal" nil "gnome-terminal")
(let* ((default-directory dir) (process-name (car command)) (proc (apply #'start-process process-name nil command))) (set-process-sentinel proc #'(lambda (proc _) (if (and (eq (process-status proc) 'exit) (or (/= ... 0) terminal-here-verbose)) (progn (message "In terminal here, command `%s` exited with error c..." (mapconcat ... command " ") (process-exit-status proc)))))) (set-process-query-on-exit-flag proc nil))
terminal-here--run-command(("gnome-terminal") "/home/juergen/emacs/site-elisp/")
(let* ((local-dir (if (file-remote-p dir) (terminal-here--tramp-path-to-directory dir) dir)) (ssh-data (terminal-here--parse-ssh-dir dir)) (terminal-command (if ssh-data (terminal-here--ssh-command ssh-data) (terminal-here--get-terminal-command local-dir)))) (if (and ssh-data inner-command) (progn (user-error "Custom commands are not currently supported over s..."))) (terminal-here--run-command (append terminal-command (if inner-command (progn (list (terminal-here--get-command-flag)))) inner-command) local-dir))
terminal-here-launch-in-directory("/home/juergen/emacs/site-elisp/" nil)
terminal-here-launch()
funcall-interactively(terminal-here-launch)
command-execute(terminal-here-launch record)
#<subr execute-extended-command>(nil "terminal-here-launch" "termi")
ad-Advice-execute-extended-command(#<subr execute-extended-command> nil "terminal-here-launch" "termi")
apply(ad-Advice-execute-extended-command #<subr execute-extended-command> (nil "terminal-here-launch" "termi"))
execute-extended-command(nil "terminal-here-launch" "termi")
funcall-interactively(execute-extended-command nil "terminal-here-launch" "termi")
command-execute(execute-extended-command)

I don't see a simple solution to this problem because there is a 1-to-1 relationship between DESKTOP_SESSION and terminal program in terminal-here--pick-linux-default.

Workaround:

(use-package terminal-here
  :ensure t
  :custom
  (terminal-here-terminal-command '("kgx"))
  (terminal-here-command-flag  "-e"))

ssh support does not work with Konsole

Reproducing

  • Set the linux terminal to 'konsole
  • Open a tramp file
  • Run terminal-here

Konsole opens and then immediately closes again.

It works perfectly for normal files.

Other useful info

  • Emacs version: 27.1
  • terminal-here version: cb561b5
  • Operating system (and version): Ubuntu 18.04

Open terminal in a python virtualenv

Hi, has anyone tried opening a terminal in a python virtualenv?

My use case is that I would like to do something like the following:

(defcustom multiple-cursors-terminal "kitty"
  "The terminal to launch pudb in."
  :type 'string)

(defun pudb ()
  "Launch pudb from emacs"
  (interactive)
  (if (executable-find "pudb3")
      (shell-command (concat multiple-cursors-terminal
                             " -e pudb3 "
                             (buffer-file-name (current-buffer))))
      (user-error "pudb3 is not found in PATH")))

Do you recommend using anything from terminal-here as a library for my use case here?

Tag Releases

Hi,

Are there any plans to continue making tagged releases or should package maintainers follow your commits?

I'm planning to package terminal-here for guix.

Doesn't work on Mac OS

The command fails on Mac OS X because the path doesn't exist. If default-directory is ~/src/temp then the open command tries to open Users/me/src/temp/~src/temp.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.