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

trash-restore mapping #579

Closed
ranebrown opened this issue Feb 9, 2021 · 9 comments
Closed

trash-restore mapping #579

ranebrown opened this issue Feb 9, 2021 · 9 comments
Labels

Comments

@ranebrown
Copy link

I'm trying to use trash-cli for delete operations using the below mappings. The delete works but restore seems to be broken for some reason. It will show the prompt to select a file to restore but then hangs after entering a number. Any ideas what is causing this?

# move file to trash
cmd trash %trash $fx
map D trash

# restore a file from trash
map U $trash-restore
@gokcehan
Copy link
Owner

@ranebrown Are you using fish? If so, #499 might be related.

@ranebrown
Copy link
Author

I'm using bash 5.1.4 and I do have set shell sh in my config. I tried using a different shell, no bashrc, different set shell option but got the same behavior. I'm using lf v20 but fairly sure I was seeing this on previous versions as well.

@gokcehan
Copy link
Owner

@ranebrown Are you on Mac? If so, #480 might be related.

@MahouShoujoMivutilde
Copy link
Contributor

MahouShoujoMivutilde commented Feb 13, 2021

This works fine for me, requires fzf.

#!/usr/bin/env sh
# (Better) interactive restore for trash-cli.

file="$(trash-list | grep "$(pwd)" | fzf | awk '{$1=$2=""; print substr($0,3)}')"

[ -z "$file" ] && exit 1

# THE KEY PART; yes, i know how ugly it looks
yes 0 | trash-restore "$file"
demo
02.18.Sunday.14.Feb.2021.mp4

@ranebrown
Copy link
Author

ranebrown commented Feb 14, 2021

I am on a Mac. I tried a mapping to that script and it does successfully restore a file but it hangs before displaying the fzf window until I press a key.

@ranebrown
Copy link
Author

Hanging seems related to FZF_DEFAULT_OPS. This seems to work:

map U ${{
FZF_DEFAULT_OPTS=""
file="$(trash-list | grep "$(pwd)" | fzf | awk '{$1=$2=""; print substr($0,3)}')"

[ -z "$file" ] && exit 1

# THE KEY PART; yes, i know how ugly it looks
yes 0 | trash-restore "$file"
}}

@thepenguinthatwants
Copy link

This works fine for me, requires fzf.

#!/usr/bin/env sh
# (Better) interactive restore for trash-cli.

file="$(trash-list | grep "$(pwd)" | fzf | awk '{$1=$2=""; print substr($0,3)}')"

[ -z "$file" ] && exit 1

# THE KEY PART; yes, i know how ugly it looks
yes 0 | trash-restore "$file"

demo
02.18.Sunday.14.Feb.2021.mp4

This works so well that I very amazed.
Very interesting different ways that these functions can be implemented.

@gokcehan
Copy link
Owner

gokcehan commented Jun 8, 2021

There has been multiple changes related to this. Feel free to reopen if the issue persists in r23.

@gokcehan gokcehan closed this as completed Jun 8, 2021
@mroavi
Copy link

mroavi commented Jan 18, 2022

Here is a version based on #579 (comment) that supports selecting multiple files to restore:

# lfrc
cmd fzf-restore ${{
    ids="$(echo -ne '\n'              | \
      trash-restore                   | \
      awk '$1 ~ /^[0-9]+/ {print $0}' | \
      fzf --multi                     | \
      awk '{print $1}'                | \
      sed -z 's/\n/,/g;s/,$/\n/')"
    echo $ids | trash-restore 
    clear
}}


map U fzf-restore

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

No branches or pull requests

5 participants