bak icon indicating copy to clipboard operation
bak copied to clipboard

Feature request: Specify baks by number from "main" bak list

Open veracioux opened this issue 4 years ago • 6 comments

Hi, I have used this program for a few days and I really like it. One thing did annoy me though. When the file I am backing up is nested deep in a directory tree under my working directory, and I want to restore it using bak down, it is not very convenient to have to specify the file's relative path.

It would be very useful if we could specify the file to restore with bak down using the number, as we can do with bak del. Maybe there is a use case to enable that for other commands as well.

In order to disambiguate a bakfile number from a file that has a number as its name, maybe we can prepend the number with something. For example bak down @1 will restore the bak file numbered 1 and bak down 1 will restore the file ./1. You may have better suggestions than this.

veracioux avatar Oct 12 '21 17:10 veracioux

You can, actually, but I'm clearly not making it obvious enough if you're here! It's only clear if you do the full help for a specific command, which ain't great.

For the record, though,

❯ bak down --help
Usage: bak down [OPTIONS] FILENAME [#]

  Restore from a .bakfile (.bakfiles deleted without '--keep')

Options:
  -k, --keep TEXT             Keep .bakfiles (optionally accepts a bakfile #;
                              can be used multiple times. Also accepts 'all'

  -q, --quietly               No confirmation prompt
  -d, -o, --destination TEXT
  --help                      Show this message and exit.

Also works on bak diff, off, open, up, and where, unless I missed a spot.

ChanceNCounter avatar Oct 12 '21 17:10 ChanceNCounter

@ChanceNCounter The documentation is clear enough. I don't think we mean the same thing. And it seems I made a mistake -- bak del doesn't do what I proposed either.

Let me explain more clearly by example:

  • My working directory is ~/project and I don't want to have to leave it
  • It contains a file ./src/library/file.py
  • I back it up like bak ./src/library/file.py
  • I edit the file
  • Back it up again
  • Edit it again
  • Now I want to restore the file

I can do bak down ./src/library/file.py 1, but I don't want to have to type out src/library/file.py. This is especially annoying if I am changing and backing up the file often. Instead, I would like to do bak down @1 or something like that, and that should automatically determine that the file I want to restore to is ./src/library/file.py.

veracioux avatar Oct 12 '21 17:10 veracioux

This is a trickier proposition. It's probably doable, but bak doesn't currently check the list order between different source files.

That is, each bakfile of the same original is reliably ordered by creation date, and their indices only change if older baks are deleted.

However, nothing currently guarantees the order of different originals in bak list when no filename is specified. It's probably consistent because it's the same database query every time, but it would need some checks to be certain, or some persistent metadata.

I have given thought to a "live" menu, with a curses-like interface that would have a persistent db connection.

Another option might be bak down --select or something. Have it bring up the list so you can specify a bakfile. But even that might be a lot if you have a bunch of bakfiles...

ChanceNCounter avatar Oct 12 '21 18:10 ChanceNCounter

@veracioux condescending if you are familiar, but it's just occurred to me that the reason this has not annoyed me so far is my somewhat determined use of bang (!) macros. I realize that even if you are familiar, most people aren't, and even fewer use them regularly, so I'm definitely going to look at ways to address this.

But, in the meantime, it makes this particular thing less annoying for me, so I should make sure you and other potential readers are aware of some fairly "basic" ones besides the ubiquitous !!:

bak down foo.txt
bak down !$ #bak down foo.txt
echo "bar baz" >> foo.txt
bak down !-2$ #bak down [final arg from 2 commands ago] --> bak down foo.txt
!-3 #[repeat 3 commands ago] --> bak down foo.txt

Still not perfect, but, especially if your prompt displays history numbers, it's an easyish way to repeat ops like these. That's why I got this far into dev without even noticing this rather obvious problem 👅

ChanceNCounter avatar Oct 14 '21 01:10 ChanceNCounter

@ChanceNCounter Thank you for that. I knew about bangs but I never used them since I use fish as my default shell. Luckily there is an extension that emulates that.

But another use case where bangs don't help is when I want to bak del a file based on its number in bak list. Sometimes I'd want to delete a bakfile that I haven't created in the current session. So it is not very convenient to navigate the shell history just to find the command I used to create the file.

veracioux avatar Oct 14 '21 16:10 veracioux

Excellent point.

ChanceNCounter avatar Oct 14 '21 17:10 ChanceNCounter