Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: mailcap configuration in zsh can't open .bk files



On Sep 2,  2:46pm, Peter Stephenson wrote:
}
} On Mon, 02 Sep 2013 09:28:26 +0800
} vinurs <haiyuan.vinurs@xxxxxxxxx> wrote:
} > It's not intelligent deciding filetype by suffix only, I'd like to write
} > functions to open flles using 'file --mime-type'
} 
} You're on your own here -- the zsh system isn't going to do this --- and
} it looks like you've got problems.  The shell allows you to define a
} command to handle other commands that aren't found, but it doesn't allow
} you define a command to handle other errors, in particular "permission
} denied", which is what you'd get if you tried to "execute" a
} non-executable file that wasn't aliased by one means or another.

If "." is not in $path and the filename is relative to $PWD, then the
error will in fact be command not found, so there might be some room to
address this in the not-found handler.

} Your best bet might be to do it in ZLE as a zle-line-finish hook.

Note that this doesn't work for complex commands, e.g., loops or "if"
constructs, unless you always use newline as the separator so that a
ZLE line ends after every simple command within the complex one.  In
some places the shell syntax makes this impossible, and history recall
won't work because the whole complex command is recalled as a single
multi-line buffer.

You might be better off creating a function or alias with a short name
and get in the habit of typing that yourself ahead of any file name you
want MIME-interpreted.

If the zle-line-finish hook is sufficient, then:

}   # HERE: cleverness for backgrounding, etc, also similar to
}   # zsh-mime-handler.
}   if [[ -n $handler ]]; then
}     BUFFER="$handler $BUFFER"
}   fi

Another possibility, to avoid inserting $handler into the buffer and
thus into the shell history, would be something like

    alias $fname="unalias $fname && $handler $fname"

This would invoke the current $handler every time upon history recall,
even if the defined handler changes between calls.



Messages sorted by: Reverse Date, Date, Thread, Author