(require 'tramp) (require 'sudo-user-path) (require 'find-command) (defun make-executable () (interactive) (shell-command (format "chmod +x %s" buffer-file-name)) ) (defun message-permissions () (interactive) (message "%s" (tramp-file-mode-from-int (file-modes buffer-file-name))) ) (defun find-whatever-file (&optional file) (interactive) (let*((the-file (or file (thing-at-point 'filename))) (true-file (file-truename the-file)) (sudo-prefix "/sudo:") (already-sudo (string-prefix-p sudo-prefix true-file)) ) (if already-sudo (find-file true-file) (let*((home-dir (getenv "HOME")) (in-home (string-prefix-p home-dir true-file)) (final-file (if in-home the-file (sudo-user-path true-file))) ) (find-file final-file) )))) (defun find-file-at-line (&optional other-window) (interactive "P") (let ((possible-filename (thing-at-point 'filename)) (find-f (if other-window #'find-file-other-window #'find-file)) ) (if (and possible-filename (file-exists-p possible-filename)) (apply find-f `(,possible-filename)) (progn (forward-char 1) (find-file-at-line) )))) (defun cats (script) (interactive "s script: ") (find-file (format "%s/scripts/%s" (getenv "HOME") script)) ) (defun find-zsh-command-file-file () "`find-file' the file in the (user) zsh environmental COMMAND_FILE. It is set in ~/.zshenv." (interactive) (let*((file (file-to-string (getenv "COMMAND_FILE"))) (search-string (file-to-string (getenv "COMMAND_STR_FILE"))) (search-string-fun-syntax (format "%s ()" search-string)) ) (when (file-exists-p file) (find-file file) (let ((start (point))) (goto-char 0) (if (search-forward search-string-fun-syntax (point-max) t) ; NOERROR (beginning-of-line-at-top) (goto-char start) ))))) (provide 'files-my)