branch: externals/ssh-deploy commit 72a503394ee43023100a6f2624ad40a4325f5938 Author: Christian Johansson <christ...@cvj.se> Commit: Christian Johansson <christ...@cvj.se>
Moved safe variables declaration to plugin, made handler functions interactive to support extended-command execution --- README.md | 21 ------------------ ssh-deploy.el | 71 +++++++++++++++++++++++++++++++++++------------------------ 2 files changed, 42 insertions(+), 50 deletions(-) diff --git a/README.md b/README.md index 6d23715..04853cc 100644 --- a/README.md +++ b/README.md @@ -31,19 +31,6 @@ Here is a list of other variables you can set globally or per directory: * `ssh-deploy-exclude-list` A list defining what paths to exclude from deployment *(list)* * `ssh-deploy-async` Enables asynchronous transfers (you need to have `async.el` installed as well) *(boolean)* -To avoid the *DirectoryVariables* warning add this: - -``` elisp - (put 'ssh-deploy-root-local 'safe-local-variable 'stringp) - (put 'ssh-deploy-root-remote 'safe-local-variable 'stringp) - (put 'ssh-deploy-debug 'safe-local-variable 'booleanp) - (put 'ssh-deploy-revision-folder 'safe-local-variable 'stringp) - (put 'ssh-deploy-automatically-detect-remote-changes 'safe-local-variable 'booleanp) - (put 'ssh-deploy-on-explicit-save 'safe-local-variable 'booleanp) - (put 'ssh-deploy-exclude-list 'safe-local-variable 'listp) - (put 'ssh-deploy-async 'safe-local-variable 'booleanp) -``` - ## A setup example * Download ssh-deploy and place it at `~/.emacs.d/ssh-deploy/` or install via `package.el` (`M-x list-packages`) from the `MELPA` repository. @@ -83,14 +70,6 @@ Set your user and group as owner and file permissions to `700`. Emacs should now :config (add-hook 'after-save-hook (lambda() (if ssh-deploy-on-explicit-save (ssh-deploy-upload-handler)) )) (add-hook 'find-file-hook (lambda() (if ssh-deploy-automatically-detect-remote-changes (ssh-deploy-remote-changes-handler)) )) - (put 'ssh-deploy-root-local 'safe-local-variable 'stringp) - (put 'ssh-deploy-root-remote 'safe-local-variable 'stringp) - (put 'ssh-deploy-debug 'safe-local-variable 'booleanp) - (put 'ssh-deploy-revision-folder 'safe-local-variable 'stringp) - (put 'ssh-deploy-automatically-detect-remote-changes 'safe-local-variable 'booleanp) - (put 'ssh-deploy-on-explicit-save 'safe-local-variable 'booleanp) - (put 'ssh-deploy-exclude-list 'safe-local-variable 'listp) - (put 'ssh-deploy-async 'safe-local-variable 'booleanp) (global-set-key (kbd "C-c C-z f") (lambda() (interactive)(ssh-deploy-upload-handler-forced) )) (global-set-key (kbd "C-c C-z u") (lambda() (interactive)(ssh-deploy-upload-handler) )) (global-set-key (kbd "C-c C-z D") (lambda() (interactive)(ssh-deploy-delete-handler) )) diff --git a/ssh-deploy.el b/ssh-deploy.el index 0a89d03..13622ee 100644 --- a/ssh-deploy.el +++ b/ssh-deploy.el @@ -3,8 +3,8 @@ ;; Author: Christian Johansson <github.com/cjohansson> ;; Maintainer: Christian Johansson <github.com/cjohansson> ;; Created: 5 Jul 2016 -;; Modified: 4 Sep 2017 -;; Version: 1.63 +;; Modified: 7 Sep 2017 +;; Version: 1.64 ;; Keywords: tools, convenience ;; URL: https://github.com/cjohansson/emacs-ssh-deploy @@ -29,33 +29,28 @@ ;;; Commentary: -;; `ssh-deploy' enables automatic deploys on explicit-save, manual uploads, renaming, +;; ssh-deploy enables automatic deploys on explicit-save, manual uploads, renaming, ;; deleting, downloads, file differences, remote terminals, detection of remote changes and remote directory browsing via TRAMP. ;; -;; To do this it progressively uses `tramp-term' and `async'. -;; By setting the variables (globally or per directory): -;; `ssh-deploy-root-local',`ssh-deploy-root-remote', `ssh-deploy-on-explicit-save' -;; you can setup a directory for `SSH' or `FTP' deployment. +;; To do this it progressively uses tramp-term and async. ;; -;; For asynchronous transfers you need to setup `~/.netrc' or key-based authorization or equivalent for automatic authentication. +;; By setting the variables (globally, per directory or per file): +;; ssh-deploy-root-local,ssh-deploy-root-remote, ssh-deploy-on-explicit-save +;; you can setup a directory for SSH or FTP deployment. ;; -;; Example contents of `~/.netrc' for `FTP': +;; For asynchronous transfers you need to setup ~/.netrc or key-based authorization or equivalent for automatic authentication. +;; +;; Example contents of ~/.netrc for FTP: ;; machine myserver.com login myuser port ftp password mypassword ;; -;; Set permissions to this file to `700' with you as the owner. +;; Set permissions to this file to 700 with you as the owner. ;; ;; - To setup a upload hook on save do this: ;; (add-hook 'after-save-hook (lambda() (if ssh-deploy-on-explicit-save (ssh-deploy-upload-handler)) )) ;; -;; - To setup automatic storing of base revisions and download of external changes do this: +;; - To setup automatic storing of base revisions and detection of external changes do this: ;; (add-hook 'find-file-hook (lambda() (if ssh-deploy-automatically-detect-remote-changes (ssh-deploy-remote-changes-handler)) )) ;; -;; - To avoid the directory variables warning add this: -;; (put 'ssh-deploy-root-local 'safe-local-variable 'identity) -;; (put 'ssh-deploy-root-remote 'safe-local-variable 'identity) -;; (put 'ssh-deploy-on-explicit-save 'safe-local-variable 'identity) -;; (put 'ssh-deploy-async 'safe-local-variable 'identity) -;; ;; - To set key-bindings do something like this: ;; (global-set-key (kbd "C-c C-z f") (lambda() (interactive)(ssh-deploy-upload-handler-forced) )) ;; (global-set-key (kbd "C-c C-z u") (lambda() (interactive)(ssh-deploy-upload-handler) )) @@ -68,14 +63,14 @@ ;; (global-set-key (kbd "C-c C-z e") (lambda() (interactive)(ssh-deploy-remote-changes-handler) )) ;; (global-set-key (kbd "C-c C-z b") (lambda() (interactive)(ssh-deploy-browse-remote-handler) )) ;; -;; An illustrative example for `SSH' deployment, /Users/Chris/Web/Site1/.dir.locals.el: +;; Here is an example for SSH deployment, /Users/Chris/Web/Site1/.dir.locals.el: ;; ((nil . ( ;; (ssh-deploy-root-local . "/Users/Chris/Web/Site1/") ;; (ssh-deploy-root-remote . "/ssh:myu...@myserver.com:/var/www/site1/") ;; (ssh-deploy-on-explicity-save . t) ;; ))) ;; -;; An example for `FTP' deployment, /Users/Chris/Web/Site2/.dir.locals.el: +;; Here is an example for FTP deployment, /Users/Chris/Web/Site2/.dir.locals.el: ;; ((nil . ( ;; (ssh-deploy-root-local . "/Users/Chris/Web/Site2/") ;; (ssh-deploy-root-remote . "/ftp:myu...@myserver.com:/var/www/site2/") @@ -84,17 +79,16 @@ ;; ;; Now when you are in a directory which is deployed via SSH or FTP you can access these features. ;; -;; ;; Here is a list of other variables you can set globally or per directory: -;; * `ssh-deploy-root-local' The local root that should be under deployment *(string)* -;; * `ssh-deploy-root-remote' The remote root that should be under deployment, should follow a `/protocol:user@host:path` format *(string)* -;; * `ssh-deploy-debug' Enables debugging messages *(boolean)* -;; * `ssh-deploy-revision-folder' The folder used for storing local revisions *(string)* -;; * `ssh-deploy-automatically-detect-remote-changes' Enables automatic detection of remote changes *(boolean)* -;; * `ssh-deploy-on-explicit-save' Enabled automatic uploads on save *(boolean)* -;; * `ssh-deploy-exclude-list' A list defining what paths to exclude from deployment *(list)* -;; * `ssh-deploy-async' Enables asynchronous transfers (you need to have `async.el` installed as well) *(boolean)* +;; * ssh-deploy-root-local - The local root that should be under deployment *(string)* +;; * ssh-deploy-root-remote - The remote root that should be under deployment, should follow a `/protocol:user@host:path` format *(string)* +;; * ssh-deploy-debug - Enables debugging messages *(boolean)* +;; * ssh-deploy-revision-folder - The folder used for storing local revisions *(string)* +;; * ssh-deploy-automatically-detect-remote-changes - Enables automatic detection of remote changes *(boolean)* +;; * ssh-deploy-on-explicit-save - Enabled automatic uploads on save *(boolean)* +;; * ssh-deploy-exclude-list - A list defining what paths to exclude from deployment *(list)* +;; * ssh-deploy-async - Enables asynchronous transfers (you need to have `async.el` installed as well) *(boolean)* ;; ;; Please see README.md from the same repository for documentation. @@ -618,12 +612,13 @@ (ssh-deploy--download-via-tramp remote local local-root))) -;; HANDLERS - the idea is that these should be bound to various Emacs commands. +;; HANDLERS - the idea is that these are interactive functions and can be bound to various Emacs commands. ;;;### autoload (defun ssh-deploy-upload-handler () "Upload current path to remote host if it is configured for SSH deployment." + (interactive) (if (and (ssh-deploy--is-not-empty-string ssh-deploy-root-local) (ssh-deploy--is-not-empty-string ssh-deploy-root-remote)) (if (and (ssh-deploy--is-not-empty-string buffer-file-name) @@ -639,6 +634,7 @@ ;;;### autoload (defun ssh-deploy-upload-handler-forced () "Upload current path to remote host if it is configured for SSH deployment." + (interactive) (if (and (ssh-deploy--is-not-empty-string ssh-deploy-root-local) (ssh-deploy--is-not-empty-string ssh-deploy-root-remote)) (if (and (ssh-deploy--is-not-empty-string buffer-file-name) @@ -654,6 +650,7 @@ ;;;### autoload (defun ssh-deploy-remote-changes-handler() "Check if local revision exists or remote file has changed if path is configured for deployment" + (interactive) (if (and (ssh-deploy--is-not-empty-string ssh-deploy-root-local) (ssh-deploy--is-not-empty-string ssh-deploy-root-remote)) (if (and (ssh-deploy--is-not-empty-string buffer-file-name)) @@ -662,6 +659,7 @@ ;;;### autoload (defun ssh-deploy-download-handler () "Download current path from remote host if it is configured for deployment." + (interactive) (if (and (ssh-deploy--is-not-empty-string ssh-deploy-root-local) (ssh-deploy--is-not-empty-string ssh-deploy-root-remote)) (if (and (ssh-deploy--is-not-empty-string buffer-file-name) @@ -678,6 +676,7 @@ ;;;### autoload (defun ssh-deploy-diff-handler () "Compare current path with remote host if it is configured for deployment." + (interactive) (if (and (ssh-deploy--is-not-empty-string ssh-deploy-root-local) (ssh-deploy--is-not-empty-string ssh-deploy-root-remote)) (if (and (ssh-deploy--is-not-empty-string buffer-file-name) @@ -694,6 +693,7 @@ ;;;### autoload (defun ssh-deploy-delete-handler () "Delete current file or directory." + (interactive) (if (and (ssh-deploy--is-not-empty-string ssh-deploy-root-local) (ssh-deploy--is-not-empty-string ssh-deploy-root-remote)) (if (and (ssh-deploy--is-not-empty-string buffer-file-name) @@ -714,6 +714,7 @@ ;;;### autoload (defun ssh-deploy-rename-handler () "Rename current file or directory." + (interactive) (if (and (ssh-deploy--is-not-empty-string ssh-deploy-root-local) (ssh-deploy--is-not-empty-string ssh-deploy-root-remote)) (if (and (ssh-deploy--is-not-empty-string buffer-file-name) @@ -738,12 +739,14 @@ ;;;### autoload (defun ssh-deploy-remote-terminal-handler () "Open remote host in TRAMP-terminal it is configured for deployment." + (interactive) (if (ssh-deploy--is-not-empty-string ssh-deploy-root-remote) (ssh-deploy-remote-terminal ssh-deploy-root-remote))) ;;;### autoload (defun ssh-deploy-remote-terminal-eshell-handler () "Open current relative path on remote host in `shell' but only if it's configured for deployment." + (interactive) (if (and (ssh-deploy--is-not-empty-string ssh-deploy-root-local) (ssh-deploy--is-not-empty-string ssh-deploy-root-remote) (ssh-deploy--is-not-empty-string default-directory)) @@ -754,6 +757,7 @@ ;;;### autoload (defun ssh-deploy-browse-remote-handler () "Open current relative path on remote host in `dired-mode' if it is configured for deployment." + (interactive) (if (and (ssh-deploy--is-not-empty-string ssh-deploy-root-local) (ssh-deploy--is-not-empty-string ssh-deploy-root-remote) (ssh-deploy--is-not-empty-string default-directory)) @@ -761,6 +765,15 @@ (local-root (file-truename ssh-deploy-root-local))) (ssh-deploy-browse-remote local-root ssh-deploy-root-remote local-path)))) +;; Mark variables as safe +(put 'ssh-deploy-root-local 'safe-local-variable 'stringp) +(put 'ssh-deploy-root-remote 'safe-local-variable 'stringp) +(put 'ssh-deploy-debug 'safe-local-variable 'booleanp) +(put 'ssh-deploy-revision-folder 'safe-local-variable 'stringp) +(put 'ssh-deploy-automatically-detect-remote-changes 'safe-local-variable 'booleanp) +(put 'ssh-deploy-on-explicit-save 'safe-local-variable 'booleanp) +(put 'ssh-deploy-exclude-list 'safe-local-variable 'listp) +(put 'ssh-deploy-async 'safe-local-variable 'booleanp) (provide 'ssh-deploy) ;;; ssh-deploy.el ends here