Skip to content

Commit

Permalink
can copy project relative path of current buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
Chen Bin committed Sep 26, 2024
1 parent 646c60f commit 5d93f2d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
23 changes: 22 additions & 1 deletion lisp/init-clipboard.el
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,33 @@ If N is not nil, copy file name and line number."
(message "%s => clipboard&kill-ring" s))))

(defun cp-fullpath-of-current-buffer ()
"Copy full path into the yank ring and OS clipboard"
"Copy full path into the yank ring and OS clipboard."
(interactive)
(when buffer-file-name
(copy-yank-str (file-truename buffer-file-name))
(message "file full path => clipboard & yank ring")))

(defun cp-root-relative-path-of-current-buffer ()
"Copy path relative to the project root into the yank ring and OS clipboard"
(interactive)
(when buffer-file-name
;; require ffip to get project root
(my-ensure 'find-file-in-project)
(let* ((root (ffip-project-root))
(file-path (file-truename buffer-file-name))
relative-path)
(cond
((not root)
(message "Can't find project root."))

((not file-path)
(message "File path of current buffer is empty."))

(t
(setq relative-path (file-relative-name file-path root))
(copy-yank-str relative-path)
(message "%s => clipboard & yank ring" relative-path))))))

(defun clipboard-to-kill-ring ()
"Copy from clipboard to `kill-ring'."
(interactive)
Expand Down
1 change: 1 addition & 0 deletions lisp/init-evil.el
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,7 @@ If N > 0 and in js, only occurrences in current N lines are renamed."
"kc" 'kill-ring-to-clipboard
"fn" 'cp-filename-of-current-buffer
"fp" 'cp-fullpath-of-current-buffer
"rp" 'cp-root-relative-path-of-current-buffer
"dj" 'dired-jump ;; open the dired from current file
"xo" 'ace-window
"ff" 'my-toggle-full-window ;; I use WIN+F in i3
Expand Down

0 comments on commit 5d93f2d

Please sign in to comment.