0

I often need to create copy of files in varios locations(, and want to avoid excessive typing). (Then I will edit them)

Basically commands are like:

cp very/long/path/to/file/my-file_with-long.name very/long/path/to/file/my-file_with-long-another.name
vim very/long/path/to/file/my-file_with-long-another.name
cp even/longer/path/to/other/location/with_another-file_and-stupid.name even/longer/path/to/other/location/with_another-file_and-stupid-copy.name
vim even/longer/path/to/other/location/with_another-file_and-stupid-copy.name

I really want to avoid changing workdir with cd and typing the same path twice. Basically I can add command into bashrc like mydup, so it will create new file and return its name, so I cam use:

vim $(mydup very/long/path/to/file/my-file_with-long.name -another)
vim $(mydup even/longer/path/to/other/location/with_another-file_and-stupid.name -copy)

But maybe I invent bicycle and there is easier way to do the same?

noonex
  • 248
  • 2
  • 10

2 Answers2

1
cp /very/long/file/path{,.bak}

vim !$

or

cpvi() {
    name=$1
    cp "${name}" "${name}.bak"
    $EDITOR "${name}.bak"
}

cpvi /very/long/file/path
ptman
  • 28,394
  • 2
  • 30
  • 45
0

You can copy a file in-place, without changing directories. E.g.

cp very-long-file-name very-long-file-name.copy
vim very-long-file-name.copy

In this case, bash-completion and tab key is your friend. I do it all the time and I never write too much.

bayindirh
  • 654
  • 1
  • 5
  • 15
  • but I must use `cd` for that (and then `cd` back) and it is really not the best solution I consider at the moment, but thx anyway – noonex Sep 28 '17 at 11:19
  • I presume that the paths are pretty unique, so bash can automatically complete it with a single `tab`? – bayindirh Sep 28 '17 at 11:22
  • Also, if you access same paths over times, you can just create symbolic links to a so-called warp-directory, so `/very/long/directory/name` becomes `/warp/first`. – bayindirh Sep 28 '17 at 11:24
  • no: there are many nested paths and many files in each – noonex Sep 28 '17 at 15:36
  • Oh, alright then. It seems that your case is different than I imagined. – bayindirh Sep 28 '17 at 22:22