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

Re: Converting relative paths to full

On 10/08/2021 22.44, Bart Schaefer wrote:
The hard part is identifying what argument strings are meant to be
interpreted as file names.

Assuming you've done that, you can convert to an absolute path pretty
easily.  Suppose for example that you know $3 is a file name.

That was a nice tip, thanks!
In cases where you have an argument like "--file=name" 

I actually don't, what I am looking for is just separated paths.

Did something like this with external tools like sed, looks like working:

	function _edit_command_to_register_full_path {
		emulate -L zsh

		for element in `echo "$1"`; do
			# Don't care about parameters
			if [[ "$element" == -* ]]; then
			if [[ -f $FULLPATH ]] || [[ -d $FULLPATH ]]; then
				REPLACED=`echo "$REPLACED" | sed "s!$element!$FULLPATH!"`
	  print -sr -- ${REPLACED%%$'\n'}

	add-zsh-hook zshaddhistory _edit_command_to_register_full_path

But having a duplication problem. The original is still applied to history.
Is there a way to just modify the string which is going to be accepted (thus respecting HIST* options), 
or should I give up this method and just use preexec_functions to modify the BUFFER directly?

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