[Top][All Lists]

[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: niku
Subject: Re: [Ranger-users] I can't get scope.sh to work properly on all files.
Date: Mon, 4 Nov 2013 16:30:57 +0530
User-agent: Mutt/1.5.21 (2010-09-15)

I can reproduce the problem and offer the following solution.

(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. 

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:

     dump() { echo "$output"; }
     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.”


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]