ranger-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Ranger-users] I can't get scope.sh to work properly on all files.


From: Somelauw .
Subject: Re: [Ranger-users] I can't get scope.sh to work properly on all files.
Date: Mon, 4 Nov 2013 17:58:24 +0100

Hmm, my native shell is zsh, but at the top of the file I found the
following shebang:
#!/usr/bin/env sh

Replacing "sh" by "bash" worked for me.
Leaving it as either "sh" or "dash" didn't work.
Leaving it as "zsh" the script crashed with an error because
apparently "file" and "tr" aren't build-in commands in zsh.

Your suggestion of using sh and printf "%s" at the same time worked as well.

I think your suggestion of using printf is best, so I left that
solution in my config file.

2013/11/4 niku <address@hidden>:
> I can reproduce the problem and offer the following solution.
>
> Summary:
> (i)  The error occurs because the shell’s built-in echo command is
>      interpreting the `\b' of `\begin'.
> (ii) The solution is to use `printf "%s" ' instead of `echo ' in
>      dump() in scope.sh.
>
> Details:
> 1) The output of scope.sh and that of manually typing the command in
> shell are different because you are (almost certainly) using two
> different `echo's. When you type the command manually, the system uses
> the system installed echo, while in the script, the `echo' built-into
> the shell is used. The system installed shell does not interpret the
> special characters by default, while the built-in shell does. (And,
> actually, there is no way to turn off the built-in echo’s
> substitutions. See below.)
>
> On my system /bin/sh is symlinked to /bin/dash. (This is probably the
> case with your system too as your output shows that your shell does
> not recognize echo’s -E option.) Have a look at the built-in echo for
> Dash at its man page. As far as I can see, there is no way to disable
> the interpretation of "special characters" in Dash. (the `echo -E'
> option is not present.)
>
> 2) The solution to this problem is to use printf. Change the line 37:
>
>
> from:
>      dump() { echo "$output"; }
> to:
>      dump() { printf "%s" "$output"; }
>
>
> You may wish to check Chris Johnson’s reply on the stackoverflow page
> for more. He says, “these variations in the behavior are the primary
> reason the use of printf is advocated over echo.”
>
> http://linux.die.net/man/1/dash
> http://stackoverflow.com/questions/2931867/echo-e-acts-differently-when-run-in-a-script-by-root-on-ubuntu
>
> On Sun, Nov 03, 2013 at 01:59:16AM +0100, Somelauw . wrote:
>> I created a small latex file test.tex:
>>
>> \begin{document}
>>     \begin{equation}
>>         h = \sqrt{n}
>>     \end{equation}
>> \end{document}
>>
>> Now, when I run scope.sh on this I get to see the following (coloured) 
>> output:
>> % ~/.config/ranger/scope.sh test.tex
>> -Eegin{document}
>>    egin{equation}
>>         h = \sqrt{n}
>>     \end{equation}
>> \end{document}
>>
>> Which obviously isn't correct. I'm not sure, but I think it might be
>> interpreting ansi colour codes twice somehow.
>>
>> By manually parsing scope.sh I figured it should be executing the
>> following command:
>> % output=$(/usr/bin/highlight test.tex --out-format=ansi); echo -E $output
>> which displays the correct (coloured) output for me:
>> \begin{document}
>>     \begin{equation}
>>         h = \sqrt{n}
>>     \end{equation}
>> \end{document
>>
>> [ truncated ]
>



reply via email to

[Prev in Thread] Current Thread [Next in Thread]