Tig: Delete files in status view

Created on 26 Jan 2012  Â·  16Comments  Â·  Source: jonas/tig

I just started using tig and found myself looking for the possibility to delete untracked files in the status view. The scrollable view is a nice way to root out generated files which should not be added to the repository. Sometimes it is easier to delete most of the known unwanted files before starting the search for the wanted ones to add. I have not found in the documentation any hints on how to delete the current highlighted file.

Most helpful comment

I use "!" a lot to revert changes to files, and I find myself naturally wanting to use the same key to remove new files. Not sure if anyone else feels the same way, but I feel like this would require more than a line in .tigrc to implement, so I might have a go at changing this myself to see how it feels :)

All 16 comments

Add the following line to you ~/.tigrc and press 'D' after highlighting the file in tig's status view:

bind status D !rm %(file)

Some users have already raised concerns about tig's support of destructive commands. Since it is easy to add support for this in ~/.tigrc I won't add delete functionality to the status view.

I concur this would be a very useful feature. Thanks for the custom key binding example, that's useful. Some thoughts:

1) it's probably a good idea to add a manual confirmation, which can be done by using rm -i in the binding

2) however it would be nicer and more consistent to have the confirmation step inside the tig interface. Is that possible (could not find it)? If not, would you consider this feature?

3) wouldn't a confirmation prompt answer the "destructive command" objection? For instance: "Are you sure you want to delete file? [YyNn]". This is already the case for ! (revert). Actually, making revert delete untracked files (after confirmation) could be a consistent solution, since this is a similar concept adapted to the context at hand (revert the addition of a file).

@dbdr sure, here you go:

bind status D !@?rm %(file)

As described in the tigrc manpage, ? asks for confirmation and @ prevents tig to display the command output, making things more integrated.

I've updated the Bindings wiki page with that example.

Very neat, thanks @vivien.

Note to others: this requires tig version >= 1.1

bind status D !@?rm %(file)

collide with

'D' toggle-date Toggle date display

so I can't use this :(. thx.

@sanrodari The proposed binding is only active in the status view and since it doesn't show any dates, there shouldn't be any need for toggling the date display.

I use "!" a lot to revert changes to files, and I find myself naturally wanting to use the same key to remove new files. Not sure if anyone else feels the same way, but I feel like this would require more than a line in .tigrc to implement, so I might have a go at changing this myself to see how it feels :)

I agree "!" would be a natural binding to remove untracked files.

Yes, files should be removed if untracked when pressing "!". You have to confirm that action, so I wouldn't be concerned about it, I'd rather expect it.

does anybody knows if it is possible to refresh the status view after deleting the file (in this bind)?

does anybody knows if it is possible to refresh the status view after deleting the file (in this bind)?

@fabioperrella have you found the way to do that?

@evmorov you can refresh pressing R

@fabioperrella oh, ok. It's not that I wanted to hear. Thanks!

Further refining the binding – require two D-key presses:

bind status DD !@?rm %(file)

why not just implement the status-revert action to also delete files behind a prompt?
! is used everywhere for destructive behavior... makes no sense to add a new D keybinding for it

Was this page helpful?
0 / 5 - 0 ratings

Related issues

proski picture proski  Â·  7Comments

djromero picture djromero  Â·  8Comments

weynhamz picture weynhamz  Â·  8Comments

elbenfreund picture elbenfreund  Â·  7Comments

dustymabe picture dustymabe  Â·  3Comments