Skip to content
This repository was archived by the owner on Nov 6, 2025. It is now read-only.

Commit 1c8519f

Browse files
Implement 'bak list' (#36)
Closes #11
1 parent d326a67 commit 1c8519f

File tree

5 files changed

+149
-66
lines changed

5 files changed

+149
-66
lines changed

README.md

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ The problem, of course, is remembering to delete that file when you're finished.
1111
**bak**'s goal is simply to obviate this process. Using **bak**, you'll be able to manage your bakfiles with four simple commands:
1212

1313
`bak my_file` - Create a bakfile in a configured location (default: XDG_DATA_HOME/bak/bakfiles, or XDG's default location)
14-
`bak up my_file` - Overwrite current `my_file.bak`, rather than creating a second .bakfile.
14+
`bak up my_file` - Overwrite current `my_file.bak`, rather than creating a second .bakfile.
1515
`bak down my_file` - Deletes `my_file` and restores it from `my_file.bak`
1616
`bak off my_file` - Deletes `my_file.bak`, confirming by default (`bak off -q` to suppress)
1717

@@ -25,29 +25,26 @@ Don't worry, they're easy to remember after a minute:
2525
All of **bak**'s commands will disambiguate between multiple copies of the same file. In other words, you can `bak my_thing.txt` as many times as you want, until you're finished working, if you'd prefer to keep multiples instead of using `bak up`. At the moment, all you've got to go by are timestamps when it asks you to pick a .bakfile, but this will improve.
2626

2727
## Additional commands and flags
28+
2829
`bak down --keep my_file` - Restores from .bakfile, does not delete .bakfile
2930
`bak diff my_file` Compare a .bakfile using `diff` (will become configurable)
30-
`bak show my_file` View a .bakfile in $PAGER
31-
`bak show --using exec my_file` View a .bakfile using `exec` (alias `--in`)
31+
`bak list`/`bak list my_file` - List all .bakfiles, or just `my_file`'s
32+
`bak open my_file` View a .bakfile in $PAGER
33+
`bak open --using exec my_file` View a .bakfile using `exec` (alias `--in`)
3234

3335
examples:
3436

35-
bak show --using cat my_file.json
36-
bak show --in nvim my_file.json
37+
bak open --using cat my_file.json
38+
bak open --in nvim my_file.json
39+
3740
`bak get-bak my_file` Get the abspath of a .bakfile, in case, for some reason, you want to pipe it somewhere
3841

3942
example (for illustrative purposes; use 'bak diff' instead):
4043

41-
diff $(bak get-bak my_file.json) my_file.json
42-
43-
## Advanced features (Not yet implemented as of Oct. 28, 2020)
44-
**bak** is also slated to support a number of flags, as well as rich output, such as:
45-
46-
`bak list` - List all .bakfiles, with a bit of metadata to help with disambiguation
47-
`bak list my_file` - List all .bakfiles *of the specified file*, with metadata
44+
diff `bak get-bak my_file.json)` my_file.json
4845

49-
## Current state (updated Oct. 31, 2020)
50-
This is a very pre-alpha version, as in, this is a spaghetti proof-of-concept. Perhaps ~~5-6~~ 12-15 hours have been spent on development so far. As such, it's only "working" in the strictest sense.
46+
## Current state (updated Jan. 20, 2020)
47+
This is a very pre-alpha version, as in, this is a spaghetti proof-of-concept. Perhaps ~~5-6~~ ~~12-15~~ 20 hours have been spent on development so far. As such, it's only "working" in the strictest sense.
5148

5249
At the moment, **bak** stores its database and your bakfiles in `$XDG_DATA_HOME/bak`. If `$XDG_DATA_HOME` is not set, its specified default is used, and your stuff ends up in `~/.local/share/bak`.
5350

bak/__main__.py

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
import click
66
from click_default_group import DefaultGroup
7-
import config
87

98
from bak import commands
109

@@ -72,16 +71,14 @@ def bak_off(filename, quietly):
7271
# TODO better output here
7372
click.echo("Operation cancelled or failed.")
7473

75-
76-
@bak.command("show", help="View a .bakfile in an external program")
77-
@click.option("--using", "--in",
74+
@bak.command("open", help="View or edit a .bakfile in an external program")
75+
@click.option("--using", "--in", "--with",
7876
help="Program to open (default: $PAGER or less)",
79-
required=False)
77+
required=False, hidden=True)
8078
@click.argument("filename", required=True, type=click.Path(exists=True))
8179
def bak_print(filename, using):
8280
commands.bak_print_cmd(filename, using)
8381

84-
8582
@bak.command("get-bak",
8683
help="Outputs the real path of a .bakfile. "
8784
"Useful for piping, and not much else.",
@@ -93,14 +90,28 @@ def bak_get(to_where_you_once_belonged):
9390
commands.bak_getfile_cmd(to_where_you_once_belonged)
9491

9592

96-
@bak.command("diff")
97-
@click.option("--using", "--in",
93+
@bak.command("diff",
94+
help="diff a file against its .bakfile")
95+
@click.option("--using", "--with",
9896
help="Program to use instead of system diff",
9997
required=False)
10098
@click.argument("filename", required=True, type=click.Path(exists=True))
10199
def bak_diff(filename, using):
102100
commands.bak_diff_cmd(filename, command=using)
103-
101+
102+
@bak.command("list",
103+
help="List all .bakfiles, or a particular file's")
104+
@click.option("--relpaths",
105+
help="Display relative paths instead of abspaths",
106+
required=False,
107+
is_flag=True,
108+
default=commands.bak_list_relpaths)
109+
@click.argument("filename",
110+
# help="List a particular file's .bakfiles",
111+
required=False,
112+
type=click.Path(exists=True))
113+
def bak_list(relpaths, filename):
114+
commands.show_bak_list(filename=filename or None, relative_paths=relpaths)
104115

105116
if __name__ == "__main__":
106117
bak()

0 commit comments

Comments
 (0)