Coder Social home page Coder Social logo

caramelhooves / teleport.el Goto Github PK

View Code? Open in Web Editor NEW
3.0 2.0 2.0 74 KB

Emacs client for teleport (goteleport.com). Connect to remote host from the comfort of your Emacs

License: GNU General Public License v3.0

Emacs Lisp 97.11% Gherkin 1.65% Python 1.24%
emacs emacs-lisp teleport

teleport.el's Introduction

Teleport for Emacs

Introduction

Gravitational Teleport is an open-source access platform that facilitates secure access to remote servers, Kubernetes clusters, and databases. This Emacs package seamlessly integrates with the Teleport command line tool (tsh), providing a similar experience to accessing remote hosts via SSH.

Key features include TRAMP integration, which enables file editing on remote hosts and file manipulation using Dired. Moreover, it offers the capability to initiate remote terminal sessions. This package is designed to enhance your Emacs environment by leveraging the power of Gravitational Teleport.

Installation and configuration

This guide assumes that you have already installed the teleport CLI and tsh is in your PATH.

The package is available on MELPA. Install it by evaluating

(package-install 'teleport)

If installation succeeds, load the package:

(require 'teleport)
(teleport-tramp-add-method)
(add-to-list 'tramp-default-user-alist '("\\`tsh\\'" nil "root"))

Users of use-package can add this piece of code to their config:

(use-package teleport
  :init
  (teleport-tramp-add-method)
  (add-to-list 'tramp-default-user-alist
             '("\\`tsh\\'" nil "root"))

  ;; Commands from this keymap are called with `default-directory' set to the remote host when called from `teleport-list-nodes' mode.
  :bind (:map teleport-list-nodes-mode-map
              ("v" . vterm)
              ("t" . term)
              ("d" . dired)))

List of teleport nodes

You can list all connected Teleport nodes by calling teleport-list-nodes command. It opens a new buffer with a table of connected nodes and their labels.

teleport-list-mode inherits its key bindings from Tabulated List Mode and adds a few mode specific bindings:

KeyAction
kHide current column
rUn-hide all hidden columns
mMark node under cursor
uUn-mark node under cursor
gUpdate the buffer without fetching list of nodes
GFetch list of nodes again and update the buffer
iCopy UUID of marked nods or the node under cursor
cOpen customize interface to customize hidden labels
/ pAdd a filter. All nodes with field not matching the regexp are removed
/ rReset the filers

Running commands

When a command is invoked in teleport-list-nodes-mode, the mode checks if the commands exist in the teleport-list-nodes-mode-map and sets the default-directory to point to the node at point. As a result, most commands will be executed locally, and only those added to the mode keymap are executed on the remote host. This prevents Emacs from unnecessarily accessing the remote host when you call unrelated commands, such as switch-buffer.

Running shell commands

Nodes could be marked by pressing m and unmarked with u. Then teleport-list-nodes-mode--do-shell-command could be used to run the same command on all of the marked nodes. If no nodes marked, run the command for the nod under cursor. For each marked node a new buffer is created. For how to organise the buffers see [Window configuration](#window-configuration).

Integration with other packages

The usefulness of this package is greatly enhanced by its integration with other Emacs packages.

Vterm

Vterm allows you to open a shell on the remote system directly from teleport-list-nodes-mode.

Under normal circumstances, no additional integration is required - it just works. However, if the remote host does not have the same shell as your local host, you may need to configure the shell to be used. If you encounter an issue where the vterm session opens and then immediately closes, consider adding this snippet to your configuration:

(with-eval-after-load 'vterm
    (add-to-list 'vterm-tramp-shells `(,teleport-tramp-method "/bin/bash")))

Dired-rsync

Dired-rsync is a fantastic package for efficiently and asynchronously copying files to and from remote hosts. With minor adjustments it could be configured to run over teleport:

(with-eval-after-load 'dired-rsync
  (defun teleport--is-file-on-teleport (filename)
    (when (tramp-tramp-file-p filename)
        (with-parsed-tramp-file-name filename v
          (string= v-method teleport-tramp-method))))

  (defun teleport-rsync-advice (orig-func sfiles dest)
    (if (or (teleport--is-file-on-teleport (car sfiles)) (teleport--is-file-on-teleport dest))
        (let ((dired-rsync-options (format "%s %s" dired-rsync-options "-e \"tsh ssh\"")))
          (funcall orig-func sfiles dest))
      (funcall orig-func sfiles dest)))
  (advice-add 'dired-rsync--remote-to-from-local-cmd :around #'teleport-rsync-advice))

Window configuration

teleport-list-nodes-mode--do-shell-command could create a lot of new buffers, they could be managed based on their name which is controlled by teleport-shell-command-buffer-name.

Create a new frame for each buffer

(setq display-buffer-alist '(("^\\*Teleport Shell Command Output: .*" display-buffer-pop-up-frame)))

If you are using Doom Emacs set-popup could be employed.

(set-popup-rule! "^\\*Teleport Shell Command Output"
  :side 'bottom
  :modeline t
  :size 0.25
  :actions '(display-buffer-in-side-window)
  :select nil
  :quit nil
  :ttl t)

teleport.el's People

Contributors

caramelhooves avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

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.