branch: elpa/helm
commit 1d58d2aef8193a48f49a99dc1415699df51cb5e4
Author: Thierry Volpiatto <[email protected]>
Commit: Thierry Volpiatto <[email protected]>
Add chown and chgrp actions to HFF
Adapt some dired functions to helm.
---
helm-files.el | 45 +++++++++++++++++++++++++++++++++++++++++++++
helm-help.el | 9 +++++++++
2 files changed, 54 insertions(+)
diff --git a/helm-files.el b/helm-files.el
index 3843b98c6a3..bd97a1bf016 100644
--- a/helm-files.el
+++ b/helm-files.el
@@ -220,6 +220,8 @@ Should not be used among other sources.")
(define-key map (kbd "M-K") 'helm-ff-run-kill-buffer-persistent)
(define-key map (kbd "M-T") 'helm-ff-run-touch-files)
(define-key map (kbd "M-M") 'helm-ff-run-chmod)
+ (define-key map (kbd "M-O") 'helm-ff-run-chown)
+ (define-key map (kbd "M-G") 'helm-ff-run-chgrp)
(define-key map (kbd "C-c z") 'helm-ff-persistent-compress)
(define-key map (kbd "M-Z") 'helm-ff-run-compress-marked-files)
(define-key map (kbd "M-c") 'helm-ff-run-compress-to)
@@ -857,6 +859,8 @@ want to use it, helm is still providing
"Compress file(s) to archive `M-c'" 'helm-find-files-compress-to
"Compress or uncompress file(s) `M-Z'" 'helm-ff-compress-marked-files
"Change mode on file(s) `M-M'" 'helm-ff-chmod
+ "Change owner on file(s) `M-O'" 'helm-ff-chown
+ "Change group on file(s) `M-G'" 'helm-ff-chgrp
"Find file other window `C-c o'" 'helm-find-files-other-window
"Find file other frame `C-c C-o'" 'find-file-other-frame
(lambda () (and (fboundp 'tab-bar-mode)
@@ -1716,6 +1720,47 @@ the car of marked files i.e. the first marked file."
(message "Changed file mode to `%s' on %s file(s)"
smode (length candidates))))))
+(defun helm-ff--dired-marked-files (&rest _args)
+ ;; Internally dired-do-chxxx needs basenames.
+ (cl-loop for f in (helm-marked-candidates :with-wildcard t)
+ collect (helm-basename f)))
+
+(defun helm-ff--dired-get-filename (&rest _args)
+ ;; Internally dired-do-chxxx needs basenames.
+ (helm-aif (helm-get-selection) (helm-basename it)))
+
+(defun helm-ff-dired-do-chxxx (&rest args)
+ "Variation of `dired-do-chxxx' for helm."
+ (cl-letf (((symbol-function 'dired-get-marked-files)
+ #'helm-ff--dired-marked-files)
+ ((symbol-function 'dired-do-redisplay)
+ #'ignore)
+ ((symbol-function 'dired-get-filename)
+ #'helm-ff--dired-get-filename))
+ (let (dired-click-to-select-mode)
+ (apply #'dired-do-chxxx args))))
+
+(defun helm-ff-chown (_candidate)
+ "Variation of `dired-do-chown' for helm."
+ (with-helm-default-directory helm-ff-default-directory
+ (when (and (memq system-type '(ms-dos windows-nt))
+ (not (file-remote-p default-directory)))
+ (error "chown not supported on this system"))
+ (helm-ff-dired-do-chxxx "Owner" dired-chown-program 'chown nil)))
+
+(defun helm-ff-chgrp (_candidate)
+ "Variation of `dired-do-chgrp' for helm."
+ (with-helm-default-directory helm-ff-default-directory
+ (when (and (memq system-type '(ms-dos windows-nt))
+ (not (file-remote-p default-directory)))
+ (error "chown not supported on this system"))
+ (helm-ff-dired-do-chxxx "Group" "chgrp" 'chgrp nil)))
+
+(helm-make-command-from-action helm-ff-run-chown "Change owner on file(s)."
'helm-ff-chown)
+(helm-make-command-from-action helm-ff-run-chgrp "Change group on file(s)."
'helm-ff-chgrp)
+(put 'helm-ff-run-chown 'helm-only t)
+(put 'helm-ff-run-chgrp 'helm-only t)
+
(defun helm-find-files-other-window (_candidate)
"Keep current-buffer and open files in separate windows.
When a prefix arg is detected files are opened in a vertical
diff --git a/helm-help.el b/helm-help.el
index 996c1b057e8..3708ff3cbcf 100644
--- a/helm-help.el
+++ b/helm-help.el
@@ -1183,6 +1183,13 @@ mode or letters, see 'chmod' man page for more infos.
NOTE: Another way to change modes on files in helm-find-files is
running `\\<helm-find-files-map>\\[helm-ff-run-switch-to-shell]' and use
'chmod' directly.
+*** Change owner and/or group on files
+
+Change owner of marked files with
`\\<helm-find-files-map>\\[helm-ff-run-chown]' and group with
`\\<helm-find-files-map>\\[helm-ff-run-chgrp]'.
+To change both at the same time use e.g. \"user:user\" at prompt.
+If you have not the rights to do this, you may have an error (see dired-log),
in this case
+open the directory as root with tramp methods sudo or su to operate.
+
*** Delete files
You can delete files without quitting helm with
@@ -1308,6 +1315,8 @@ If `all-the-icons' package is installed, turning on
|\\[helm-ff-run-hardlink-file]|Hardlink files.
|\\[helm-ff-run-relsymlink-file]|Relative symlink Files.
|\\[helm-ff-run-chmod]|Change mode on Files.
+|\\[helm-ff-run-chown]|Change owner on Files.
+|\\[helm-ff-run-chgrp]|Change group on Files.
|\\[helm-ff-run-delete-file]|Delete Files.
|\\[helm-ff-run-touch-files]|Touch files.
|\\[helm-ff-run-kill-buffer-persistent]|Kill buffer candidate without leaving
Helm.