I want to copy an image file from one github repo to another. The source and destination file paths are deeply nested within the repo (eg. copy ~/code/repo1/src/components/A/components/B/common/components/C/images/image1.png to ~/code/repo2/src/components/D/images/image1.png, so I want a convenient way to construct the file paths without manually typing them.

Ideally the solution would involve fuzzy file finding so that it's easy to construct the path to image1.png without having to type the directory names.

  • 2
    The question does not seem to be about Emacs.
    – Drew
    Commented May 20, 2019 at 23:14
  • What if I appended " in emacs" to the title? The idea is this comes up when I'm editing code and I'd like to accomplish it without leaving emacs
    – mark
    Commented May 21, 2019 at 17:02
  • Consider asking it on StackOverflow or another StackExchange site. It's a shell question, regardless of where you execute the shell command. You can use shell within Emacs, of course, and if/when you get the shell answer you can apply it to your use of shell in Emacs.
    – Drew
    Commented May 21, 2019 at 17:32

1 Answer 1


This solution constructs a cp command in a shell using helm-ls-git to fuzzy-find the source and destination.

  • M-x customize-variable helm-ls-git-fuzzy-match set to on
  • M-x shell to open a shell in a new window
  • open any file in repo1, then M-x helm-ls-git-ls and fuzzy-find image1.png
  • C-u C-c C-k (helm-kill-selection-and-quit) to copy the file path from helm
  • switch to the shell window, type cp and C-y to yank the image1.png source file path
  • open any file in repo2, then M-x helm-ls-git-ls and fuzzy-find a file within the destination directory (or something close to it)
  • C-u C-c C-k (helm-kill-selection-and-quit) to copy the destination path from helm
  • switch back to the shell buffer and C-y to paste. Modify the destination appropriately (eg. removing filename) if the previous step returned an inexact destination.

This will result in a cp command that you can execute to copy the file. Afterwards, kill the shell and its buffer.

You may bind helm-ls-git-ls to a convenient shortcut if desired (for example, (global-set-key [?\C-c ?f] (quote helm-ls-git-ls))).

  • 1
    All of this to avoid typing two pathnames? And why do it in shell and not open the two directories in emacs and use dired-dwim-target?
    – NickD
    Commented May 21, 2019 at 4:03
  • Thanks, this is a good solution, I did not know about dired-dwim-target. Also explained here emacs.stackexchange.com/a/5604
    – mark
    Commented May 21, 2019 at 21:32

Not the answer you're looking for? Browse other questions tagged or ask your own question.