Coder Social home page Coder Social logo

Comments (14)

vermaden avatar vermaden commented on June 8, 2024 1

Sure.

I also added some tests with other editors.

Using it with Geany does not work at all. FreeBSD's vi(1) also does not work but its probably vi(1) fault.

It does work with vim(1) but output in the terminal is at strange offset and you need to type reset to have working terminal after it.

Here are the outputs:

Files that I am testing on:

% ls -la
total 84K
drwxr-xr-x  2 vermaden vermaden   7 2022-10-12 09:35 ./
drwxr-xr-x 44 vermaden vermaden 277 2022-10-17 14:58 ../
-rw-r--r--  1 vermaden vermaden   0 2022-10-10 21:43 asd1
-rw-r--r--  1 vermaden vermaden   0 2022-10-10 21:43 asd2
-rw-r--r--  1 vermaden vermaden   0 2022-10-10 21:43 asd3
-rw-r--r--  1 vermaden vermaden   0 2022-10-10 21:43 asd4
-rw-r--r--  1 vermaden vermaden   0 2022-10-10 21:43 asd5

Geany: I renamed asd1 to asd1a but does not work.

% command gls -1|env EDITOR=geany renamer
Error: No replacements found

% command ls -1|env EDITOR=geany renamer 
Error: No replacements found

FreeBSD vi(1):

% command ls -1|env EDITOR=vi renamer   
ex/vi: Vi's standard input and output must be a terminal
Error: Editor terminated unexpectedly. Aborting.

%  command gls -1|env EDITOR=vi renamer
ex/vi: Vi's standard input and output must be a terminal
Error: Editor terminated unexpectedly. Aborting.

vim(1):

% command ls -1|env EDITOR=vim renamer  
Vim: Warning: Input is not from a terminal
(...)
"/tmp/.tmpZwhWL4" 5L, 26B written

The following replacements were found:

                                      asd1 -> asd1a

                                                   Execute these renames?:
> Yes
       No
           Edit
                 Reset

% command ls -1|env EDITOR=vim renamer         
Vim: Warning: Input is not from a terminal
(...)
"/tmp/.tmpzwYNO9" 5L, 25B written

The following replacements were found:

                                      asd1a -> asd1

                                                   Execute these renames?:
> Yes
       No
           Edit
                 Reset

Hope that helps.

Regards.

from pipe-rename.

vermaden avatar vermaden commented on June 8, 2024 1

Hi.

Do not be sorry mate. We all do that because of passion in the expense of our personal lifes and time.

That syntax - env EDITOR=vim renamer * - works well with both vi(1) and vim(1) editors. The Geany still does not work - but I just assume that it is Geany's fault.

Thank You for working solution.

Regards.

from pipe-rename.

in0ni avatar in0ni commented on June 8, 2024 1

Hey @assarbad , I have not gotten around to report this yet -- but now (for a few weeks) renamer does not work at all:

  • renamer * (which worked)
  • ls | renamer
  • setting stty sane before hand

All return:
Error: No replacements found

No version change in the tool, let me know if you need any assistance debugging

UPDATE: seems to be an issue on my end. My editor is "kak", but editor is set to "kcr edit", so using -e "kak" works 😅

from pipe-rename.

vermaden avatar vermaden commented on June 8, 2024

These files for sure. If I face other problematic files I will let you know.

from pipe-rename.

assarbad avatar assarbad commented on June 8, 2024

@vermaden this being FreeBSD and seeing the % prompt I'll guess Zsh. But could you fill in some blanks by executing the following from your shell:

$SHELL --version; env|grep -P '^(LC_|LANG|EDITOR)'

(grep -E should also do, but I don't know if this is supported by whatever grep comes out of the box in recent FreeBSDs)

Just thinking out loud: perhaps there is a misunderstanding between how ls/find output the name and how renamer sees them.

Also, could you try find -type f|sort|env EDITOR=geany renamer instead of the ls -1|...?

from pipe-rename.

vermaden avatar vermaden commented on June 8, 2024

Hi,

yes - its ZSH.

Here is the ouuput:

% $SHELL --version; env|grep -P '^(LC_|LANG|EDITOR)'
zsh 5.9 (amd64-portbld-freebsd13.1)
usage: grep [-abcDEFGHhIiLlmnOoPqRSsUVvwxz] [-A num] [-B num] [-C num]
        [-e pattern] [-f file] [--binary-files=value] [--color=when]
        [--context=num] [--directories=action] [--label] [--line-buffered]
        [--null] [pattern] [file ...]

% $SHELL --version; env|grep -P -E '^(LC_|LANG|EDITOR)'
zsh 5.9 (amd64-portbld-freebsd13.1)
usage: grep [-abcDEFGHhIiLlmnOoPqRSsUVvwxz] [-A num] [-B num] [-C num]
        [-e pattern] [-f file] [--binary-files=value] [--color=when]
        [--context=num] [--directories=action] [--label] [--line-buffered]
        [--null] [pattern] [file ...]

% $SHELL --version; env|grep -E '^(LC_|LANG|EDITOR)' 
zsh 5.9 (amd64-portbld-freebsd13.1)
LC_COLLATE=C
EDITOR=vi
LANG=C.UTF-8
LC_ALL=en_US.UTF-8

I believe the last one is the one you were looking for.

Also - I use the GNU ls(1) as default so I will also show you the FreeBSD ls(1) variant below.

% bls -1 | env EDITOR=geany renamer
Error: No replacements found

% ls -1 | env EDITOR=geany renamer 
The following input files do not exist:
asd1
asd2
asd3
asd4
asd5

Error: Nonexisting input files. Aborting.

% which ls   
ls: aliased to  gls -p --color=always --time-style=long-iso --group-directories-first --quoting-style=literal

% which bls               
bls: aliased to /bin/ls -p -G -D "%Y.%m.%d %H:%M"

Regards.

from pipe-rename.

assarbad avatar assarbad commented on June 8, 2024

@vermaden cool, that was useful! Could you try one more thing please:

command gls -1|env EDITOR=geany renamer

Feel free to also try it with the FreeBSD ls, e.g. like so:

command ls -1|env EDITOR=geany renamer

The command is a builtin of Zsh (but also Bash) which ensures that not the alias or builtin or function, but the external command is used.

The reason I ask is because you have aliased your ls to the underlying gls --color=always ... and that particular switch may be the cause for the issue. I cannot tell for certain, since I don't see your terminal, but chances are that somehow those escape sequences end up garbling the names as seen by renamer. Just a theory, though.

Since you use a UTF-8 based locale, it's not about encodings, which was another possible suspect here.

from pipe-rename.

assarbad avatar assarbad commented on June 8, 2024

Sorry, @vermaden ... lost sight of this. Apologies.

If Geany has any indication of the code page or encoding it "thinks" the edited file is, could you have a look at that and paste it here?! If it "thinks" it's something wacky instead of UTF-8, I could imagine that being the issue. Your shell/terminal are configured for a UTF-8 locale and theoretically Geany should honor that setting, too. But what do I know? 😉

The issue you see with Vim on the terminal seems related to #54, I would reckon. Presumably because you are piping the names into the command. As both vi and Vim point out your input isn't coming from a terminal as it expects. Probably Vim does the best to comply whereas vi gives up with an error?

Have you tried env EDITOR=vim renamer * instead from the same directory? It should do the correct thing and AFAIK the shell should also do the right thing for you when it comes to file names with embedded whitespace.

Edit: to ensure anyone can try to reproduce this, could you please try to take a recursive copy of the folder containing those files somewhere (probably something like cp -ar <source-folder> <target-folder>/), then use truncate - as truncate -s 0 <filename> - to set all the files to zero size (that's why you'll want a copy on which to do it) and then tar them up? NB: GitHub only allows tar files with the .tar.gz extension, not even .tgz works.

Anyway, this should enable anyone to pick up a FreeBSD and try to reproduce it, given the locale settings agree (I think some UTF-8 locale will be fine even).


And one more thing, if you were to use (GNU) find you could use something like find ${optional_dir_to_search} -type f -exec renamer {} + or the more portable find ${optional_dir_to_search} -type f -exec renamer {} \;. But for the piping scenario something making renamer usable with find ... -print0|xargs -0 ... could be even more desirable.

from pipe-rename.

in0ni avatar in0ni commented on June 8, 2024

Hello, I'm having a similar issue. In my case my shell is also zsh, and my editor is Kakoune:

Running ls | renamer

  • I get an empty editor
  • if I set $EDITOR to vim, I get an error message "Vim: Warning: Input is not from a terminal", it takes some time and I am able to get the file list in editor
  • if I use bash, the behavior is exactly the same in both cases

Running renamer *

  • works well in all cases

Running echo -e "one.file\ntwo.file" | renamer (running touch one.file two.file beforehand)

  • same issue as first examples, in zsh/bash and vim/kakoune

I tried to follow this thread to determine what the issue could be, but nothing really stood out.

Also I found this here: https://xplr.dev/en/awesome-hacks (under batch rename)... Ideally I would like to use selections, but since this does not work, I just modified the code to always use renamer *

from pipe-rename.

assarbad avatar assarbad commented on June 8, 2024

@in0ni your third example suggests this can solely be attributed to how renamer treats stdin/stdout/stderr.

So it could be related to #54 ...

from pipe-rename.

assarbad avatar assarbad commented on June 8, 2024

One more remark, @in0ni ... you can use (this syntax is particular to GNU find):

find -type f -exec renamer {} +

... or:

find -type f -print|xargs renamer

However, I think the second one could cause the issue with the terminal getting messed up. I am still investigating what's going on with that.

from pipe-rename.

in0ni avatar in0ni commented on June 8, 2024

Hello @assarbad,

I appreciate you continuing to look into this. Seems like something is up with the way renamer is dealing with pipes (with the over a decade of *nix use I'm still not 100% proficient or knowledgeable with this).

I will mention that I find this tool to be very powerful combined with a modal editor like Kakoune. At times I have to rename many files with different patterns and this approach has been the quickest and most flexible. So thanks for this tool!

So far I have not had the need to pass a specific list since I can use the power of the editor to filter out what I need. So I'm using renamer * for all my cases and have stopped trying to get other syntax to work.

from pipe-rename.

assarbad avatar assarbad commented on June 8, 2024

Also on this ticket, in case someone is still reading.

Workaround (not a fix!) If you encounter the messed up terminal issue, for now you can use stty sane. After that everything should work as expected in the terminal again.

from pipe-rename.

assarbad avatar assarbad commented on June 8, 2024

I suppose you have built it yourself? What tag/revision? I think there was no formal version change in the crate for some reason, I also noticed that :-|

from pipe-rename.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.