Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
477 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<link rel="alternate" | ||
type="application/rss+xml" | ||
href="https://www.birkey.co/rss.xml" | ||
title="RSS feed for https://www.birkey.co/"> | ||
<title>Why Eshell - Part 3</title> | ||
<meta name="author" content="Kasim Tuman"> | ||
<meta name="referrer" content="no-referrer"> | ||
<link href= "static/style.css" rel="stylesheet" type="text/css" /> | ||
<link rel="icon" href="static/favicon.ico"> | ||
<link rel="apple-touch-icon-precomposed" href="static/birkey_logo.png"> | ||
<link rel="msapplication-TitleImage" href="static/birkey_logo.png"> | ||
<link rel="msapplication-TitleColor" href="#0141ff"> | ||
<link rel="alternate" type="application/rss+xml" title="RSS Feed for birkey.co" href="/rss.xml" | ||
<meta http-equiv="content-type" content="application/xhtml+xml; charset=UTF-8"> | ||
<meta name="viewport" content="initial-scale=1,width=device-width,minimum-scale=1"></head> | ||
<body> | ||
<div id="preamble" class="status"><br><center> | ||
<div style="display: inline-block; vertical-align:middle;"> | ||
<a href="https://www.birkey.co/index.html" style="text-decoration: none;"><b>BIRKEY CONSULTING</b><br> | ||
</a><hr/><div style="text-align: justify;display: inline-block; width: 100%;"> | ||
<a class="title" href="https://www.birkey.co/resume.html">ABOUT</a> <a class="title" href="https://github.com/oneness">GITHUB</a> <a class="title" href="https://www.birkey.co/rss.xml">RSS</a> <a class="title" href="https://www.birkey.co/archive.html">ARCHIVE</a> <a class="title" href="https://paypal.me/ktuman">DONATE</a></div></div> | ||
</center><br><br> | ||
<div style="margin-bottom: 3ch;text-transform: none;"></div></div> | ||
<div id="content"> | ||
<div class="post-date">10 Jul 2021</div><h1 class="post-title"><a href="https://www.birkey.co/2021-07-10-why-eshell-part-3.html">Why Eshell - Part 3</a></h1> | ||
<p> | ||
If you have been following my `Why Eshell` series, you might be | ||
wondering about interactive ido completion for eshell. Since Eshell | ||
buffer is just a regular emacs buffer, we can compose few emacs | ||
builtin functionalities to bend it to our command line work flow. | ||
Following is all the code you need. Note that it is heavily commented | ||
so you can understand what is happening. | ||
</p> | ||
<div class="org-src-container"> | ||
<pre class="src src-emacs-lisp">(defun kshell-with-name (&optional name) | ||
;; creates an eshell buffer with `kshell' as the default name. Take | ||
;; optional name to override | ||
(let ((m (->> (or name "kshell") | ||
(format "*%s*")))) | ||
(if (get-buffer m) | ||
(pop-to-buffer m) | ||
(progn | ||
(eshell) | ||
(rename-buffer m))))) | ||
|
||
(defun kshell (&optional cmd buff-name send-input) | ||
;; interactive fn that you can call via M-x or hotkey. It detects | ||
;; current project root to start eshell buffer if no `buff-name' is | ||
;; given. You can control how the `cmd` gets insert only or insert | ||
;; and executed using `send-input` flag. Ex. Useful for further | ||
;; editing. | ||
(interactive) | ||
(let ((dir (projectile-project-root))) ;; you need projectile | ||
(if buff-name | ||
(kshell-with-name buff-name) | ||
(kshell-with-name)) | ||
(eshell/clear-scrollback) | ||
(insert (format "cd %s" (or dir "~/"))) | ||
(eshell-send-input) | ||
(insert (format "%s" cmd)) | ||
(when send-input (eshell-send-input)))) | ||
|
||
(defun krun (cmd) | ||
;; eshell command history with ido completion. Assign it to a hot | ||
;; key say, F12 and you will get a search-able command history that | ||
;; you can execute just by doing ido interactive search. | ||
(interactive | ||
(list | ||
(ido-completing-read | ||
"Enter cmd to run (append ##name for buffer name): " | ||
(let ((history nil)) | ||
;; We have to build up a list ourselves from the ring vector. | ||
(dotimes (index (ring-length keshell-history-global-ring)) | ||
(push (ring-ref keshell-history-global-ring index) history)) | ||
;; Show them most-recent-first. | ||
(setq history (nreverse history)))))) | ||
(let* ((cmds (split-string cmd "##")) ;; you need s.el lib | ||
(tag (or (-> cmds second) | ||
"kshell")) | ||
(buff-name (-> tag s-chomp s-trim))) | ||
(kshell cmd buff-name))) | ||
</pre> | ||
</div> | ||
<p> | ||
Here is the screen recording in action: | ||
<img src="https://www.birkey.co/images/eshell-ido-interactive.gif" alt="eshell-ido-interactive.gif"> | ||
</p> | ||
|
||
<p> | ||
I am using F12 to invoke `krun` and my cross session eshell history | ||
shows up in the minibuffer where I can use ido completion to select a | ||
command that I can run. As an added benefit, above code allows one to | ||
bring a eshell buffer with specific name by adding ##name at the end | ||
of the command if one wants to have the command run in a dedicated | ||
buffer. | ||
</p> | ||
<div class="taglist"><a href="https://www.birkey.co/tags.html">Tags</a>: <a href="https://www.birkey.co/tag-eshell.html">eshell</a> <a href="https://www.birkey.co/tag-emacs.html">emacs</a> </div></div> | ||
<div id="postamble" class="status"><br><center> | ||
<div style="display: inline-block; vertical-align:middle;"></div></div> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
#+title: Why Eshell - Part 3 | ||
#+date: <2021-07-10 10:18> | ||
#+filetags: eshell emacs | ||
|
||
If you have been following my `Why Eshell` series, you might be | ||
wondering about interactive ido completion for eshell. Since Eshell | ||
buffer is just a regular emacs buffer, we can compose few emacs | ||
builtin functionalities to bend it to our command line work flow. | ||
Following is all the code you need. Note that it is heavily commented | ||
so you can understand what is happening. | ||
#+begin_src emacs-lisp | ||
(defun kshell-with-name (&optional name) | ||
;; creates an eshell buffer with `kshell' as the default name. Take | ||
;; optional name to override | ||
(let ((m (->> (or name "kshell") | ||
(format "*%s*")))) | ||
(if (get-buffer m) | ||
(pop-to-buffer m) | ||
(progn | ||
(eshell) | ||
(rename-buffer m))))) | ||
|
||
(defun kshell (&optional cmd buff-name send-input) | ||
;; interactive fn that you can call via M-x or hotkey. It detects | ||
;; current project root to start eshell buffer if no `buff-name' is | ||
;; given. You can control how the `cmd` gets insert only or insert | ||
;; and executed using `send-input` flag. Ex. Useful for further | ||
;; editing. | ||
(interactive) | ||
(let ((dir (projectile-project-root))) ;; you need projectile | ||
(if buff-name | ||
(kshell-with-name buff-name) | ||
(kshell-with-name)) | ||
(eshell/clear-scrollback) | ||
(insert (format "cd %s" (or dir "~/"))) | ||
(eshell-send-input) | ||
(insert (format "%s" cmd)) | ||
(when send-input (eshell-send-input)))) | ||
|
||
(defun krun (cmd) | ||
;; eshell command history with ido completion. Assign it to a hot | ||
;; key say, F12 and you will get a search-able command history that | ||
;; you can execute just by doing ido interactive search. | ||
(interactive | ||
(list | ||
(ido-completing-read | ||
"Enter cmd to run (append ##name for buffer name): " | ||
(let ((history nil)) | ||
;; We have to build up a list ourselves from the ring vector. | ||
(dotimes (index (ring-length keshell-history-global-ring)) | ||
(push (ring-ref keshell-history-global-ring index) history)) | ||
;; Show them most-recent-first. | ||
(setq history (nreverse history)))))) | ||
(let* ((cmds (split-string cmd "##")) ;; you need s.el lib | ||
(tag (or (-> cmds second) | ||
"kshell")) | ||
(buff-name (-> tag s-chomp s-trim))) | ||
(kshell cmd buff-name))) | ||
#+end_src | ||
Here is the screen recording in action: | ||
https://www.birkey.co/images/eshell-ido-interactive.gif | ||
|
||
I am using F12 to invoke `krun` and my cross session eshell history | ||
shows up in the minibuffer where I can use ido completion to select a | ||
command that I can run. As an added benefit, above code allows one to | ||
bring a eshell buffer with specific name by adding ##name at the end | ||
of the command if one wants to have the command run in a dedicated | ||
buffer. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.