* relative path
@ 2018-02-21 21:53 Ray Andrews
2018-02-22 2:16 ` Ray Andrews
0 siblings, 1 reply; 2+ messages in thread
From: Ray Andrews @ 2018-02-21 21:53 UTC (permalink / raw)
To: Zsh Users
Like anyone, when I'm working on something complicated I make copious
backups, and if I find I've introduced some bug I run previous versions
to see where the bug was introduced. But I often have six terminals
openat once, with different versions running here and there and it's
easy to forget which terminal is running which backup, so I do this:
In file 'test' then being backed up to 'test,1' 'test,2' etc:
function my_function ()
{
_vvar=`whence -vS $0 | cut --delimiter=' ' --fields=7-`
_ooutput=`ls -g --time-style=+%F/%T $_vvar | cut --delimiter=' '
--fields=5-`
echo -e "Function: $0 \nFile: $_ooutput"
# code below:
}
$ . ./test; my_function
Function: my_function
File: 2018-02-21/13:07:10 ./test
$ cp test test,2
$ . ./test,2; my_function
Function: my_function
File: 2018-02-21/13:07:20 ./test,2
So, as various copies of the function run I can see the file that was
sourced and its date, and I know which is newer than which. There's just
one small problem and that's if I source the files via a relative path
that path is the one seen by 'whence' and if I run the function out of
the directory where the file is located, whence still sees the relative
path but of course 'ls' now can't find the file. This isn't a big
problem in practice but I'm curious if there would be a solution. Some
way of capturing the absolute path even when I actually use a relative
path. I think there is, I have a niggling I've used it but I can't
remember.
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: relative path
2018-02-21 21:53 relative path Ray Andrews
@ 2018-02-22 2:16 ` Ray Andrews
0 siblings, 0 replies; 2+ messages in thread
From: Ray Andrews @ 2018-02-22 2:16 UTC (permalink / raw)
To: zsh-users
On 21/02/18 01:53 PM, Ray Andrews wrote:
> path. I think there is, I have a niggling I've used it but I can't
> remember.
>
>
>
>
_full=${0:a}
function my_function ()
{
_vvar=`whence -v $0 | cut --delimiter=' ' --fields=7-`
_ooutput=`ls -g --time-style=+%F/%T $_full | cut --delimiter=' '
--fields=5-`
echo -e "Function: $0 \nFile: $_ooutput"
}
Ha! I knew about " ${0:a} " but I thought it only applied to functions.
Clever thing reports the absolute path of files too:
$ my_function
Function: my_function
File: 2018-02-21/18:04:30 /aWorking/Zsh/Source/Wk/test
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2018-02-22 2:16 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-02-21 21:53 relative path Ray Andrews
2018-02-22 2:16 ` Ray Andrews
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).