;;; -*- lexical-binding: t -*- ;; ;; this file: ;; https://dataswamp.org/~incal/emacs-init/ide/find-command-zsh.el (require 'file-write-to) (require 'get-search-string) (require 'simple) (require 'window-incal) (defun shell-command-silent (cmd) (process-file shell-file-name nil nil nil shell-command-switch cmd) ) (defun find-command-zsh (&optional cmd) "Find the source for a zsh cmd. This requires an external zsh script to work, see https://dataswamp.org/~incal/conf/.zsh/find-command" (interactive) (or cmd (setq cmd (get-search-string "zsh"))) (let*((search-cmd (format "find-zsh-command %s" cmd)) (file-data-path (getenv "CMD_FILE")) (erase-data-cmd (format "echo -n > %s" file-data-path)) ) (shell-command-silent erase-data-cmd) (shell-command-silent search-cmd) (let ((file (file-to-string file-data-path)) (cmd-search-str (format "%s ()" cmd)) (als-search-str (format "alias .*%s" cmd)) (case-fold-search nil) ) (unless (string= file "") (find-file file) (goto-char (point-min)) (when (or (search-forward-regexp cmd-search-str nil t) (search-forward-regexp als-search-str nil t) ) (beginning-of-line-at-top) ))))) (defun find-zsh-command-file-file () "`find-file' the file in the shell env CMD_FILE. It is set in ~/.zshenv." (interactive) (let*((file (file-to-string (getenv "CMD_FILE"))) (search-string (file-to-string (getenv "CMD_STR"))) (search-string-fun-syntax (format "%s ()" search-string)) ) (when (file-exists-p file) (find-file file) (let ((beg (point))) (goto-char (point-min)) (if (search-forward search-string-fun-syntax nil t) (beginning-of-line-at-top) (goto-char beg) ))))) (provide 'find-command-zsh)