On 10/17/07, Fernando Canizo <[EMAIL PROTECTED]> wrote:
> Axel Liljencrantz wrote:
> >> This makes mc left you on the last directory you were navigating
> >> inside mc when it exits, pretty useful. All the magic is done by the
> >> '-P' switch.
> >> ...
> >> so in fish I do this in my config.fish (which *is* being sourced):
> >>
> >>     function mc
> >>         set mctmpfile (tempfile)
> >>         /usr/bin/mc -P $mctmpfile
> >>         cd (cat $mctmpfile)
> >>         rm -f $mctmpfile
> >>         set mctmpfile
> >>     end
> >>
> >> But it doesn't work.
> >
> > I suspect that the empty file problem you're seeing is actually a
> > regession bug in fish. Specifically, I belive the file in question
> > does contain the file name, but does not end with a newline, and that
> > the fish prompt 'swallows' the output. You can test this theory by
> > calling echo after cat-ing the file. The next fish release will fix
> > this problem.
>
> Indeed, that was one of the problems. And thanks for taking the issue
> into consideration for the next release.
>
> > The following script seems to work correctly for me, though the choice
> > of filename leaves something to be desired:
> >
> > function mc
> >   set tmpfile ~/ggg
> >   command mc -P $tmpfile
> >   cd (cat $tmpfile)
> >   rm $tmpfile
> > end
>
> fish swallowing the cat of a newlineless line was an issue, but not the
> actual problem, but it was a problem that complicated for me the finding
> of a solution.
>
> The problem was using the command 'tempfile' (it comes in debianutils
> package on my gentoo).
>
> mc creates the file given on the -P switch upon exit, if the file
> exists, it silently fails to create it and left you in the directory
> where you were before issuing mc.
>
> So the filename given to the -P switch must be a nonexistent file.
>
> I modified your version of the function to this:
>
> set tmpfile /tmp/mcpwd-(random)
>
> If not using 'random' or using the same file name, the -P switch stops
> working as soon as you start mc twice (or more). It only work the first
> time you exit mc.
>
> Though 'random' works it annoys me that it doesn't assure the uniqueness
> of the filename. I know it will be very difficult to get 'random' give
> two equal numbers, but I would be more comfortable knowing it's
> *impossible*.

I have the same kind of irrational worry sometimes. Something like
this might help:

function tempfile2
    while true
        set -l filename $argv[1]/tmp-$USER-(hostname)-(%self)-(random)
        if test ! -f $filename
            echo $filename
            return
        end
    end
end

The $USER-(hostname)-(%self) bit is there to minimize the possibility
of clashes when multiple processes using tempfile2 at once. It should
be reasonably uncommon for two processes on different systems to share
the same username, the same hostname, both processes having the same
pid and sharing the same file namespace.

If you dont care about such cases, you can cheat and (ab)use the
tempfile command:

function tempfile2
    set -l res (tempfile)
    rm $res
    echo $res
end


>
> > Hope this helps!
>
> Sure it did, thank you :)
>
> Would you consider adding a new command to fish that gives a unique file
> name on a given directory? I found myself in the past several times with
> this necessity and I think it would be pretty useful to have it in the
> shell itself.
>
> Also it will not bloat fish since you'll only need to wrap a call to
> tempnam(3) in the command. I know I could do a simple C program, but
> that would be extern, I really think it should go into fish, however I
> may be overlooking a simpler solution made with what is already
> provided, so I wanna hear you opinions.

Actually, one of the fish design criteria is to push as much as
possible out of the shell proper and into shellscript functions or
even external commands. The fish binary is roughly half the size of
bash, and one of the reasons for this is that fish does not have
builtin versions of common commands like help, test or printf, or a
built in regexp matcher, math mode, etc.. The way I see it, all of
these things are better done outside the shell, because the user has a
greater freedom to use, extend or replace the tools in the shell
'toolkit', because buggy implementations of the tools don't risk
crashing the shell proper, because magic syntax like the bash math
mode means more stuff to learn and memorize and because it makes the
fish codebase more modular and easier to work with.

Fish has a number of external commands shipping with it, like
fish_pager,  which is the completion pager, the set_color utility for
changing output color on the terminal, mimedb for quering the mimetype
database for filetypes and so on. As you say, it would be pretty easy
to make a small C program that works like tempfile, but I think the
best solution is one of the shellscripts above.


Axel

>
> --
> Fernando Canizo - http://muriandre.homelinux.org/~conan/
>

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
Fish-users mailing list
Fish-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/fish-users

Reply via email to