[Emacs] Move Eshell functions to aliases

Many Eshell functions do not need to be declared as such and can do just
fine as Eshell aliases. This commit moves all these functions to the
'eshell-alias' file
This commit is contained in:
Lucien Cartier-Tilet 2020-12-02 17:33:00 +01:00
parent bdc4e543cf
commit c46fcd3db7
Signed by: phundrak
GPG Key ID: BD7789E705CB8DCA
2 changed files with 56 additions and 114 deletions

View File

@ -35,3 +35,24 @@ alias flac youtube-dl -x --audio-format flac --audio-quality 0 $*
alias mp3 youtube-dl -x --audio-format flac --audio-quality 0 $* alias mp3 youtube-dl -x --audio-format flac --audio-quality 0 $*
alias wget wget -c $* alias wget wget -c $*
alias rsync rsync -ruvtEhl --progress $* alias rsync rsync -ruvtEhl --progress $*
alias remove sudo pacman -Rscnd $*
alias gpumeminfo grep -i --color memory /var/log/Xorg.0.log
alias diskspace sudo df -h | grep -E "sd|lv|Size" | sort
alias meminfo free -m -l -t
alias cpuinfo lscpu
alias pscpu ps auxf | sort -nr -k 3
alias pscpu10 ps auxf | sort -nr -k 3 | head -10
alias psmem ps auxf | sort -nr -k 4
alias psmem10 ps auxf | sort -nr -k 4 | head -10
alias q exit
alias exti exit
alias exi exit
alias clean clear
alias vi emacs
alias vim emacs
alias ed emacs
alias nano emacs

View File

@ -1421,61 +1421,6 @@ For some ease of use, Ill also declare ~list-buffers~ as an alias of ~ibuffer
(defalias 'list-buffers 'ibuffer) (defalias 'list-buffers 'ibuffer)
#+END_SRC #+END_SRC
***** System monitoring
:PROPERTIES:
:CUSTOM_ID: User_Configuration-Eshell-Aliases-System_monitoring-ee01b070
:END:
Similar to ~meminfo~, we also have ~gpumeminfo~ so we can get a quick look at the memory-related logs of our X session.
#+BEGIN_SRC emacs-lisp
(defun eshell/gpumeminfo (&rest $args)
(eshell/grep "-i" "--color" "memory" "/var/log/Xorg.0.log"))
(defun eshell/diskspace ()
(shell-command "sudo df -h | grep -E \"sd|lv|Size\" | sort"))
#+END_SRC
I also declared ~cpuinfo~ an alias of ~lscpu~ in order to keep consistent with ~meminfo~.
#+BEGIN_SRC emacs-lisp
(defun eshell/meminfo ()
(shell-command "free -m -l -t"))
#+END_SRC
~pscpu~ gives us information on what the CPU is running right now, and I also declared ~cpuinfo~ an alias of ~lscpu~ in order to keep consistent with ~meminfo~.
#+BEGIN_SRC emacs-lisp
(defun eshell/cpuinfo ()
(shell-command "lscpu"))
#+END_SRC
~pscpu10~ limits that to the top 10 threads.
#+BEGIN_SRC emacs-lisp
(defun eshell/pscpu ()
(shell-command "ps auxf | sort -nr -k 3"))
(defun eshell/pscpu10 ()
(shell-command "ps auxf | sort -nr -k 3 | head -10"))
#+END_SRC
Similarly, ~psmem~ gives us information on the memory usage of the current threads, and ~psmem10~ only the ten most important threads in terms of memory usage.
#+BEGIN_SRC emacs-lisp
(defun eshell/pscpu ()
(shell-command "ps auxf | sort -nr -k 4"))
(defun eshell/pscpu10 ()
(shell-command "ps auxf | sort -nr -k 4 | head -10"))
#+END_SRC
***** System management (packages and services)
:PROPERTIES:
:CUSTOM_ID: User_Configuration-Eshell-Aliases-System_management_(packages_and_services)-afb6d9d3
:END:
The first command is ~remove~ which removes a package and its dependencies from the system.
#+BEGIN_SRC emacs-lisp
(defun eshell/remove (&rest $args)
(phundrak/concatenate-shell-command "sudo pacman -Rscnd"
$args))
#+END_SRC
***** Other
:PROPERTIES:
:CUSTOM_ID: User_Configuration-Eshell-Aliases-Other-bd88ca97
:END:
~mkcd~ is a function that allows me to create a directory and ~cd~ into it at the same time. ~mkcd~ is a function that allows me to create a directory and ~cd~ into it at the same time.
#+begin_src emacs-lisp #+begin_src emacs-lisp
(defun eshell/mkcd ($directory) (defun eshell/mkcd ($directory)
@ -1483,26 +1428,6 @@ The first command is ~remove~ which removes a package and its dependencies from
(cd $directory)) (cd $directory))
#+end_src #+end_src
***** Typos
:PROPERTIES:
:CUSTOM_ID: User_Configuration-Eshell-Aliases-Typos-c7bfe6eb
:END:
~q~ is a shorthand for ~exit~. ~exti~ and ~exi~ are for typos when I type ~exit~.
#+BEGIN_SRC emacs-lisp
(defun eshell/q (&rest $args)
(eshell/exit $args))
(defun eshell/exti (&rest $args)
(eshell/exit $args))
(defun eshell/exi (&rest $args)
(eshell/exit $args))
#+END_SRC
~clean~ is also a typo of ~clear~ I often make. Lets fix this:
#+BEGIN_SRC emacs-lisp
(defun eshell/clean (&rest $args)
(eshell/clear $args))
#+END_SRC
**** Custom functions **** Custom functions
:PROPERTIES: :PROPERTIES:
:CUSTOM_ID: User_Configuration-Eshell-Custom_functions-79d98245 :CUSTOM_ID: User_Configuration-Eshell-Custom_functions-79d98245
@ -1528,19 +1453,15 @@ I also want to be able to have multiple instances of Eshell opened at once. For
:PROPERTIES: :PROPERTIES:
:CUSTOM_ID: User_Configuration-Eshell-Custom_functions-Redirect_text_editors_to_Emacs-dff362c6 :CUSTOM_ID: User_Configuration-Eshell-Custom_functions-Redirect_text_editors_to_Emacs-dff362c6
:END: :END:
I still have some muscle memory telling me to open nano, ed, or vim, and sometimes I even try to type ~emacs~ in the terminal, which is stupid with Eshell since Im already inside Emacs. So, for each of these text editors, lets make the command open the files in Emacs. I still have some stupid muscle memory telling me to open ~emacs~ in the terminal, which is stupid with Eshell since Im already inside Emacs. So, lets open each file passed to the ~emacs~ command and bury the eshell buffer (well get back to it later).
#+BEGIN_SRC emacs-lisp #+BEGIN_SRC emacs-lisp
(defun eshell/emacs (&rest $files) (defun eshell/emacs (&rest $files)
"Open a file in a new buffer. Old habits die hard" "Open a file in a new buffer. Old habits die hard"
(if (null $files) (if $files
(bury-buffer)
(mapc #'find-file (mapc #'find-file
(mapcar #'expand-file-name (mapcar #'expand-file-name
(eshell-flatten-list (reverse $files)))))) (eshell-flatten-list (reverse $files))))
(defalias 'eshell/vi 'eshell/emacs) (bury-buffer)))
(defalias 'eshell/vim 'eshell/emacs)
(defalias 'eshell/ed 'eshell/emacs)
(defalias 'eshell/nano 'eshell/emacs)
#+END_SRC #+END_SRC
**** Environment variables **** Environment variables