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.

   3=${3:P}
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

		REPLACED="$1"
		for element in `echo "$1"`; do
			# Don't care about parameters
			if [[ "$element" == -* ]]; then
				continue
			fi
			FULLPATH="${element:P}"
			if [[ -f $FULLPATH ]] || [[ -d $FULLPATH ]]; then
				REPLACED=`echo "$REPLACED" | sed "s!$element!$FULLPATH!"`
			fi
		done
	  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