Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
veracioux opened this issue Oct 12, 2021 · 6 comments
Open

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

veracioux opened this issue Oct 12, 2021 · 6 comments
Labels
enhancement New feature or request

Comments

@veracioux
Copy link

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.

@ChanceNCounter
Copy link
Collaborator

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 ChanceNCounter changed the title Allow specifying bakfile number with commands other than del Improve help: Make clear that you can use bakfile numbers for most commands Oct 12, 2021
@ChanceNCounter ChanceNCounter added documentation Improvements or additions to documentation enhancement New feature or request labels Oct 12, 2021
@veracioux
Copy link
Author

@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.

@ChanceNCounter
Copy link
Collaborator

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 ChanceNCounter changed the title Improve help: Make clear that you can use bakfile numbers for most commands Feature request: Specify baks by number from "main" bak list Oct 12, 2021
@ChanceNCounter ChanceNCounter removed the documentation Improvements or additions to documentation label Oct 12, 2021
@ChanceNCounter
Copy link
Collaborator

@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 👅

@veracioux
Copy link
Author

@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.

@ChanceNCounter
Copy link
Collaborator

Excellent point.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants