lf icon indicating copy to clipboard operation
lf copied to clipboard

Paste Async File From Wiki does not work

Open thetwistedlogic opened this issue 3 years ago • 3 comments

I attempted to add the paste-async function from the Wiki. However it does not work; I spent a while troubleshooting but I was unable to figure out why.

In case it proves useful to anyone, here is my implementation of the function.

cmd paste-async &{{
    mode="$(cat $HOME/.local/share/lf/files | head -1)"
    case "$mode" in
        copy) 
            while IFS= read -r line
            do 
                cp -rn -- "$line" .
            done  < "$HOME/.local/share/lf/files"
            ;;
        move) 
            while IFS= read -r line
            do 
                mv -n -- "$line" .
            done  < "$HOME/.local/share/lf/files"
            ;;
    esac

    dunstify "Succesful file transfer!" "$files" -i folder
    rm ~/.local/share/lf/files
    lf -remote "send reload"
}}

I know it's not the best but it works. If a more experienced person would like to rewrite it, feel free.

This is my first time opening up an issue on a large project so I apologize if this is out of place.

thetwistedlogic avatar Apr 05 '22 19:04 thetwistedlogic

When I tried your script, it works as expected, so I'm not sure why it is not working for you. What shell are you using (did you do set shell ... or set shellopts ...)? To make it easier to troubleshoot, you can change cmd paste-async &{{ to cmd paste-async !{{ to see the output of the script.

By the way, the first line of ~/.local/share/lf/files is copy or move, so the first iteration will fail. But that shouldn't prevent the script from working. Also, the $files variable is not set anywhere, but again, that shouldn't be a problem.

en0mem avatar May 18 '22 19:05 en0mem

Apologies for not making it clear. I posted my implementation which works. I was just saying that the implementation of paste async on the wiki doesn't work for me.

Creating this issue was just to say that the wiki's version doesn't work and to offer a solution, that could perhaps be used in the wiki (after someone more experienced cleans it up).

thetwistedlogic avatar May 19 '22 14:05 thetwistedlogic

Okay, I see what you mean. The implementation in the wiki works for me, so I'm not sure what's wrong. It would be super helpful if you could provide your shell and shellopts settings.

en0mem avatar May 20 '22 04:05 en0mem

The wiki version works for me too. Although one difference I noticed is that in your version you use while IFS= read -r line to obtain the filenames, which works for filenames with spaces in them.

Actually the wiki implementation can also handle filenames with spaces in them, but you have to set the ifs option to "\n". This is actually mentioned at the top of the Tips section of the wiki, but is easy to miss.

I don't think there's actually any issue so I will close this, but feel free to reopen if you want to discuss further.

joelim-work avatar Oct 01 '23 07:10 joelim-work