[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:
parent
bdc4e543cf
commit
c46fcd3db7
@ -1,37 +1,58 @@
|
|||||||
alias s systemctl $*
|
alias s systemctl $*
|
||||||
|
|
||||||
alias nmcli nmcli -p -c auto $*
|
alias nmcli nmcli -p -c auto $*
|
||||||
|
|
||||||
alias chgrp chgrp --preserve-root $*
|
alias chgrp chgrp --preserve-root $*
|
||||||
alias chmod chmod --preserve-root $*
|
alias chmod chmod --preserve-root $*
|
||||||
alias chown chown --preserve-root $*
|
alias chown chown --preserve-root $*
|
||||||
|
|
||||||
alias df df -H $*
|
alias df df -H $*
|
||||||
alias du du -ch $*
|
alias du du -ch $*
|
||||||
|
|
||||||
alias grep grep --color=auto $*
|
alias grep grep --color=auto $*
|
||||||
alias ls exa -halg@ --group-directories-first --git $*
|
alias ls exa -halg@ --group-directories-first --git $*
|
||||||
alias lns ln -si $*
|
alias lns ln -si $*
|
||||||
alias mkdir mkdir -p $*
|
alias mkdir mkdir -p $*
|
||||||
|
|
||||||
alias rm rm -I $*
|
alias rm rm -I $*
|
||||||
alias rmd rm --preserve-root -Ir $*
|
alias rmd rm --preserve-root -Ir $*
|
||||||
alias rmdf rm --preserve-root -Irf $*
|
alias rmdf rm --preserve-root -Irf $*
|
||||||
alias rmf rm --preserve-root -If $*
|
alias rmf rm --preserve-root -If $*
|
||||||
|
|
||||||
alias cdebug cmake -DCMAKE_BUILD_TYPE=Debug $*
|
alias cdebug cmake -DCMAKE_BUILD_TYPE=Debug $*
|
||||||
alias crelease cmake -DCMAKE_BUILD_TYPE=Release $*
|
alias crelease cmake -DCMAKE_BUILD_TYPE=Release $*
|
||||||
alias g++ g++ -Wall -std=c++17 $*
|
alias g++ g++ -Wall -std=c++17 $*
|
||||||
alias gcc gcc -Wall -std=c11 $*
|
alias gcc gcc -Wall -std=c11 $*
|
||||||
alias clang++ clang++ -Wall -std=c++17 $*
|
alias clang++ clang++ -Wall -std=c++17 $*
|
||||||
alias clang clang -Wall -std=c11 $*
|
alias clang clang -Wall -std=c11 $*
|
||||||
|
|
||||||
alias dcd docker-compose down
|
alias dcd docker-compose down
|
||||||
alias dcu docker-compose up
|
alias dcu docker-compose up
|
||||||
alias dcud docker-compose up -d
|
alias dcud docker-compose up -d
|
||||||
alias dcp docker-compose pull
|
alias dcp docker-compose pull
|
||||||
|
|
||||||
alias flac youtube-dl -x --audio-format flac --audio-quality 0 $*
|
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
|
||||||
|
@ -1421,61 +1421,6 @@ For some ease of use, I’ll 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. Let’s 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 I’m already inside Emacs. So, for each of these text editors, let’s 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 I’m already inside Emacs. So, let’s open each file passed to the ~emacs~ command and bury the eshell buffer (we’ll 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))))))
|
(bury-buffer)))
|
||||||
(defalias 'eshell/vi 'eshell/emacs)
|
|
||||||
(defalias 'eshell/vim 'eshell/emacs)
|
|
||||||
(defalias 'eshell/ed 'eshell/emacs)
|
|
||||||
(defalias 'eshell/nano 'eshell/emacs)
|
|
||||||
#+END_SRC
|
#+END_SRC
|
||||||
|
|
||||||
**** Environment variables
|
**** Environment variables
|
||||||
|
Loading…
Reference in New Issue
Block a user