Restic ls to tree browser / restore helper

So playing with Restic and NCDU got me thinking… it would be cool if Restic could pipe something akin to --ncdu (or exactly ncdu’s format) to a helper application that would let you browse just like NCDU, but upon hitting “return” it would exit and spit out the restore command.

Say you browse to /Volumes/Users/akrabu/Desktop/my-stuff in the helper app, then hit “return” (or some key combo) - it would then take you back to the terminal with “restic restore :/Volumes/Users/akrabu/Desktop/my-stuff -t .” filled in and ready for you.

Wonder if NCDU could be forked for this? Unfortunately I’m nowhere near talented enough to pull this off myself, but… it sure would be handy!

The functionality I’m thinking of is similar to what fzf does, if anyone uses that to search their files in the terminal. Whatever line is highlighted gets spit out to the terminal when you hit return.

EDIT: Might make more sense for me to make a request on NCDU’s site for a switch that outputs selected paths / the last path upon exit?

EDIT2: Nope, nevermind, that’s probably not happening any time soon lol

(just my opinon) unless size is somehow more important than the ability to fuzzy search on the name, using ncdu is not worth it – I normally just pipe the list into fzf and feed the output to restic restore, as you said.

However, I was intrigued by the idea of somehow using ncdu. Here’s what I came up with but this is a horrible kludge:

  • use gdu instead of ncdu; it takes the same output file as ncdu (i.e., restic ls --ncdu will work) and produce a display similar to ncdu
  • create a simple bash script in ~/tmp/xdg-open which contains basically echo "$1" > ~/tmp/gdu.out; make it executable
  • run PATH=$HOME/tmp:$PATH gdu -f restic.json
  • select the file or dir you want and hit o (in gdu that runs xdg-open on the file, but we mangled the PATH so it will run our script instead)
  • exit gdu and get your filename from ~/tmp/gdu.out

I did say this was a horrible kludge didn’t I :slight_smile:

2 Likes

I don’t know why, but every time I restic ls (snapshot-ID) | fzf -i for some reason it freezes and never works. I have to restic ls (snapshot-ID) > files.txt then cat files.txt | fzf -i which makes no sense but it’s the only way I can get it to work.

I mostly like NCDU a little better because you can walk the tree. It’s not just search, it’s seeing the heirarchy.

That trick does work, though! ChatGPT led me to try something similar, but yes it is kludgy haha

TIL fzf exists and it works with restic. This is really cool! :upside_down_face:

Edit: By the way, it works fine for me with | directly.

1 Like

A bit off topic but… can anyone confirm ‘restic ls | fzf’ works on MacOS? I swear it hangs on even the tiniest of snapshots on all my Macs unless I dump it to a text file then ‘cat’ it to fzf.

Honestly that would be good enough for me, though I do like the tree navigation of NCDU

I see. On the rare cases I needed this I just mounted the repo and used my normal file manager, but there may be some tradeoffs there.

Ah yes, normally that would be my go-to as well - though presently it’s a little broken under MacOS Sonoma. On top of that, my repository is 10TB and struggles to mount with my measly 16GB of RAM. And other times I’m operating solely over SSH, to boot. That’s mostly why it comes to mind haha

oh; I have no knowledge of any apple systems but 10 TB is huge anywhere I guess.

I’d say the “horrible kludge” is looking pretty good now :wink:

1 Like