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

Re: Converting relative paths to full




On 10/08/2021 23.39, Gürkan wrote:
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?

Oh nevermind, I've found an old answer related to it[0]:

Now it works good enough:

	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'}
	  return 1
	}

	add-zsh-hook zshaddhistory _edit_command_to_register_full_path

Also needed to change -s to -S.

Thanks again.

[0]: https://www.zsh.org/mla/users/2011/msg00754.html


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