From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.4 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FROM,HTML_MESSAGE,MAILING_LIST_MULTI, NICE_REPLY_A,RCVD_IN_DNSWL_MED,UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 7380 invoked from network); 10 Aug 2021 21:40:59 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 10 Aug 2021 21:40:59 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1628631659; b=nrYGEM8mZ+LaPeIy6JsYPQHxw9CaoJskqP5GSh3rAV3oeb5nJ+ckvj2k+PFGYUY0WSD1wp/ngy TEM+sRNLl0aUIyrLYG48d0ocr/vSmwPFsl19/GUStKTyGbP/riauK7L3yWODeCdyfr5mYwowun pon+x5IZJV5iHRLYBzafkXd0oNV33IZP3vSX0Yjijq+XarsMXV3ZgNAIBQq250aWY5BXaq9opV YAuhIihMsyfv5Nsg+ZQ9L0L35x73Ng9CzgUAQfC3a2EIbMvEw9YN3aIS7YpYfdX1rKfkOWnNJA VwSP/3VnlR0kqPQNR/BFRgRB039ZabRPgNBQuILg8fCKVg==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail-lf1-f52.google.com) smtp.remote-ip=209.85.167.52; dkim=pass header.d=gmail.com header.s=20161025 header.a=rsa-sha256; dmarc=pass header.from=gmail.com; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20210803; t=1628631659; bh=LRlZiN+C1jc3T+kMAQ+vSbEsHIUjCduHVGSSBo66O6s=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Content-Type:In-Reply-To:MIME-Version:Date:Message-ID:From: References:Cc:To:Subject:DKIM-Signature:DKIM-Signature; b=KFReIcyf+LDSgKRp5f+3k4g6tSfRNzMfuOrKau41DgBvFons4IXWda97dkB6V4qGJUuV0v6zwT Nb12AVFROGYgqAFlt7YZGcPGOK/i5vsXKzpKhK/+zqOjMyPpNMkyDJ7JdGA6kMWjn3Y9UMOfWg heOagcSvvuPVmbmXnSxWO6zOnVvwzr7+UYbi8Z+beJDq1AdygW5RIy6zwh8GV6XDdSZEMP0ozJ Ex1p+2glBkOyOxu42q0Uhmmz/h7Dgo5ZpZjNTw7iXNS8gYHNAcBvefsKV4ZTXc9H1PQ9zF/LDU vBtRf2sZZviH/dz/oy6XdBMsiajJx9dMhmgCe2tWB5HczA==; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=zsh.org; s=rsa-20210803; h=List-Archive:List-Owner:List-Post:List-Unsubscribe: List-Subscribe:List-Help:List-Id:Sender:Content-Type:In-Reply-To:MIME-Version :Date:Message-ID:From:References:Cc:To:Subject:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=mrHIGyz+1hfwHvmJ7JmqN/75EpNFNipfKtN3dfsXqME=; b=hxYI1KnMXmyIA0WZxQv/rMXs8D IzhmsmJO7jecr2grZsuHcSYjXVCTnqAD622WanVgW0yyeFdcu1uI+9JkxHytZ00m4MK6DiRjNGBHC 7VM4ohyrbNRdC/vE1PExMZmWJiEz+ByU7GDQ0e/yFsjYWq0CEL52stHDO8ptPbke8Bu5e7hnmSkgG QVC2q9zhcFTHGug5M8c1HY1+y020iUuJo+6id97xiruAXy5JUMsb4YRt0WE6gz5/LJb5dsdXnzSLm bwQdcd0hdAUdyuPNLN7CELIvcPgYYYLWjOSMWhrjJSYoeAu56PbSDkXYD+ODYPkxd7RUNPpyozE7Z EbL/08Kw==; Received: from authenticated user by zero.zsh.org with local id 1mDZUX-0003ZL-Q1; Tue, 10 Aug 2021 21:40:57 +0000 Authentication-Results: zsh.org; iprev=pass (mail-lf1-f52.google.com) smtp.remote-ip=209.85.167.52; dkim=pass header.d=gmail.com header.s=20161025 header.a=rsa-sha256; dmarc=pass header.from=gmail.com; arc=none Received: from mail-lf1-f52.google.com ([209.85.167.52]:38672) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1mDZTe-0002pN-Bd; Tue, 10 Aug 2021 21:40:02 +0000 Received: by mail-lf1-f52.google.com with SMTP id x27so869904lfu.5 for ; Tue, 10 Aug 2021 14:40:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language; bh=mrHIGyz+1hfwHvmJ7JmqN/75EpNFNipfKtN3dfsXqME=; b=esqNEmO/Ogp6AqYc9FVMWIQosQGjke43WDXltOpioQ2x2oSFOBBU4aNMgj8GNkmsKg 1qzW0nCK3lYtu6JomDmPmqiQocy7K1gpHd/6mpdcTHBPTm6EuZa3MZfEI/DW518jOWdw dAuYFJ1BPkCln2Zleu6/FCJbwGpL1UNM72SdpgxGWbh2g5ZjAsyc7UPai3CPrc1CIIks x3p4TsrFCMzIizHpLY1ykiVdLs6F2tIySgOoKwtUJwCo08q2YQ0kpPLjJqnMXbo5ZNA4 v3qgu2VUjq36MAvrA05B2IWUP9PpjNM4+Mw1iQAhpFpB3tetEH7KJ+0FBGZST4tNetZ8 o2Ow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language; bh=mrHIGyz+1hfwHvmJ7JmqN/75EpNFNipfKtN3dfsXqME=; b=hnPt16G7qolo01EwIapaCF3Fl5ovIdSNJSNPaYZiFJRyfkT9FmgcPJ7KfhYz2jqqjH kmCMT+AHgT8x1sSaIMHE8jHn89leph9jF1vJ6F4qEvTr9p7aezeuMpaeiEswGB+WD4rj prw1fUz2VGgWav3EAcPaIMKIJhnxtBKJqJUWNgidAJ5Q/gB9PYuwJTIwc17R6GRL9vha WPfUQbCjj6YUZKDxPwxFRjq6qn7qsOuc1ZP4BLwTddB5Zl8D9xY40yTqE+4n5w38abtf qDKdKf+L8WJg/zkiHi+c/oUNO5YK8lBqHXipxx9HMf0MgJ0M16xfgPOwM45ij5zDkl64 mMfw== X-Gm-Message-State: AOAM533wEiG6ByBoolRso0J9tq3PRt12wt5/6ZqfyVPfgW4cF1fObp7E I3Ii3PehXam7qT/GnfLPd9zQpGzPx7JTtA== X-Google-Smtp-Source: ABdhPJwMNQ+ssI8i4LhHhOGcdZLnLGeBGKF4jc5iJbYAEcQocBghoAXOoP1fp6tjLxukzVhGSO7U/A== X-Received: by 2002:a05:6512:23a2:: with SMTP id c34mr24759364lfv.342.1628631601514; Tue, 10 Aug 2021 14:40:01 -0700 (PDT) Received: from ?IPv6:2001:16b8:682b:2900:f209:66bf:32ce:890a? (200116b8682b2900f20966bf32ce890a.dip.versatel-1u1.de. [2001:16b8:682b:2900:f209:66bf:32ce:890a]) by smtp.gmail.com with ESMTPSA id c8sm298689lfv.159.2021.08.10.14.40.00 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 10 Aug 2021 14:40:00 -0700 (PDT) Subject: Re: Converting relative paths to full To: Bart Schaefer Cc: Zsh Users References: From: =?UTF-8?Q?G=c3=bcrkan?= Message-ID: <68cd3b1c-0a75-af79-f262-e5dd32233c55@gmail.com> Date: Tue, 10 Aug 2021 23:39:59 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.12.0 MIME-Version: 1.0 In-Reply-To: Content-Type: multipart/alternative; boundary="------------D8F3058F9D4FF66B2EBEDFA3" Content-Language: en-US X-Seq: 26901 Archived-At: X-Loop: zsh-users@zsh.org Errors-To: zsh-users-owner@zsh.org Precedence: list Precedence: bulk Sender: zsh-users-request@zsh.org X-no-archive: yes List-Id: List-Help: List-Subscribe: List-Unsubscribe: List-Post: List-Owner: List-Archive: This is a multi-part message in MIME format. --------------D8F3058F9D4FF66B2EBEDFA3 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit 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? --------------D8F3058F9D4FF66B2EBEDFA3 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: 7bit


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?
--------------D8F3058F9D4FF66B2EBEDFA3--