Closed nebulosa2007 closed 11 months ago
In other words we should have a machine/bash readable output.
Totally agree.
Let's also make the oneline mode output json to keep it structured.
This will solve both the issues -
Also it's very easy to restructure with jq
.
As a quick illustration we could then have something like this -
$ src/yabsnap.sh list-json
{"comment":"pacman -S jq","config_file":"/etc/yabsnap/configs/root.conf","file":{"prefix":"/.snapshots/root-","timestamp":"20231029172350"},"source":"/","trigger":"I"}
{"comment":"","config_file":"/etc/yabsnap/configs/home.conf","file":{"prefix":"/.snapshots/home-","timestamp":"20231026183029"},"source":"/home","trigger":"S"}
{"comment":"","config_file":"/etc/yabsnap/configs/home.conf","file":{"prefix":"/.snapshots/home-","timestamp":"20231027234159"},"source":"/home","trigger":"S"}
It is also easily restructured by jq
(which may then also be strimed to fzf
), for instance -
$ src/yabsnap.sh list-json | jq '.file.prefix+.file.timestamp
"/.snapshots/root-20231029172350"
"/.snapshots/home-20231026183029"
"/.snapshots/home-20231027234159"
Hope this proposed addition makes sense.
Implemented a new arg to do this, yabsnap list-json
.
Bug report :)
==> Starting check()...
Created: /tmp/yabsnap_config_test_da2dmmcs
.........F...
======================================================================
FAIL: test_list_json (code.snap_operator_test.SnapOperatorTest.test_list_json)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/nebulosa/.cache/pikaur/build/yabsnap/src/yabsnap-2.0.10/src/code/snap_operator_test.py", line 131, in test_list_json
self.assertEqual(
AssertionError: Lists differ: ['{"c[89 chars]tamp":"20230213031000"},"source":"snap_source","trigger":"S"}'] != ['{"c[89 chars]tamp":"20230213054000"},"source":"snap_source","trigger":"S"}']
First differing element 0:
'{"co[87 chars]stamp":"20230213031000"},"source":"snap_source","trigger":"S"}'
'{"co[87 chars]stamp":"20230213054000"},"source":"snap_source","trigger":"S"}'
- ['{"comment":"comment","config_file":"config_file","file":{"prefix":"/tmp/nodir/@home-","timestamp":"20230213031000"},"source":"snap_source","trigger":"S"}']
? ^^
+ ['{"comment":"comment","config_file":"config_file","file":{"prefix":"/tmp/nodir/@home-","timestamp":"20230213054000"},"source":"snap_source","trigger":"S"}']
? ^^
----------------------------------------------------------------------
Ran 13 tests in 0.020s
FAILED (failures=1)
==> ERROR: A failure occurred in check().
Aborting...
Sorry - I saw it and fixed it, but forgot to release to AUR.
Released now, 2.0.11 should install fine.
Thx, now works as expected!
Example of usage:
yabsnap list-json | jq -r '.file.timestamp' | fzf -m --reverse --preview 'yabsnap list-json | grep {1} | jq -r .comment' | xargs -I{} sudo yabsnap --dry-run delete {}
Eye candy example:
yabsnap list-json | jq -r '.trigger+" "+.file.timestamp' | fzf -m --reverse --preview 'yabsnap list-json | grep {2} | jq -r .comment' --preview-window right:70%:wrap | xargs -I{} echo {} | cut -d' ' -f2 | xargs -I{} sudo yabsnap --dry-run delete {}
When you write
yabsnap list
it shows all information about snapshopts, but when you want delete some of them it will be not so easy, because name of snapshots is 14-digit timestamp, that really hard to enter, only copy and past.For convinience you can use the fzf in that scenario (e.g. bash alias
snapctl
):ls -d /.snapshots/*/ | sed 's/\/.snapshots\///g;s/\/$//g' | fzf -m --reverse --preview 'echo -n $(basename {1})": "; cat /.snapshots/{1}-meta.json | echo $(tr -d "\"}{")' --preview-window right:70%:wrap | xargs -I snap sudo yabsnap delete /.snapshots/snap'
It works as expected and already could be mentined in README, but really wants use
yabsnap
withfzf
like that:yabsnap list -q | fzf ... --preview yabsnap list {1} | xargs ... yabnsap delete ...
, where:yabsnap list -q
it lists names of snapshots,yabsnap list PATH|TIMESTAMP [--oneline]
shows info only for one snapshot (--oneline
- comma-separared info in one line)Any thoughts?