分享一些 alias 和 function

如题,欢迎分享其它的 snippets ,不知道有没有人水过

alias e="emacsclient -t -a ''"
alias ec="emacsclient -c -a ''"
alias E="SUDO_EDITOR=\"emacsclient -c -a 'emacs'\" sudo -e"
function magit () {cd "${1:-${PWD}}";ec -e "(magit)";}
function dired () {ec -e "(dired \"$1\")";}

现在我都是用的 rofi 用我 alias 的那个 ec 命令来启动 emacs:

zsh -i -c ec

如图:

3 个赞

rofi如何把这些function和alias作为候选?

rofi 有历史记录功能,你输入过一次,它就会记得你输入过了,因此,你只要输入:

zsh -i -c "${ALIASES_OR_FUNCTIONS}"

即可,rofi会记住

如果输入错误,可以按下 shift + Delete(注意不是backspace) 来删除这个历史记录,重新输入就好了

我来分享一下在 eshell 下的函数。

(defmacro my/interactive (fmt &rest args)
  "A function wrapper of `interactive' with FMT and ARGS."
  `(call-interactively (lambda ,args
                         (interactive ,fmt)
                         (list ,@args))))

(defun eshell/icd ()
  "Interactive cd."
  (let ((dir (my/interactive "Dcd " dir)))
    (cl-destructuring-bind (d) dir
      (insert (concat "cd " d)))
    (eshell-send-input)))

配合 ivy 就可以在 eshell 输入 icd 来交互式的切换当前目录了。

e() { emacsclient -a "" -t "$(realpath ${@})"; }
ee() { emacsclient -a "" -c "$(realpath ${@})" &> /dev/null & disown; }
se() { emacsclient -a "" -t "/sudo:root@localhost:""$(realpath ${@})"; }
see() { emacsclient -a "" -c "/sudo:root@localhost:""$(realpath ${@})" &> /dev/null & disown; }

我的alias也差不多,加了disown 可以打开新emacs的同时继续用终端。用的tramp path来sudo 编辑文件,不过我刚才试了一下SUDO_EDITOR,也挺好的,可能用 sudo -e 才是对的…