* More zsh tricks required please
@ 2004-06-19 12:43 zzapper
2004-06-19 13:06 ` Christian Schneider
` (2 more replies)
0 siblings, 3 replies; 10+ messages in thread
From: zzapper @ 2004-06-19 12:43 UTC (permalink / raw)
To: zsh-users
Hi,
I'm an intermediate zsh user, and can't do the whacko stuff yet.
But haven't learnt any tricks recently, last one was
> vim =some_script (from anywhere)
where the = means search paths for script location.
So please a link to a handy website, or your tips/tricks.
On the above BTW is it possible to do a
> cd =some_script (doesn't work)
to jump to the directory??
zzapper (vim, cygwin, wiki & zsh)
--
vim -c ":%s/^/WhfgTNabgureRIvzSUnpxre/|:%s/[R-T]/ /Ig|:normal ggVGg?"
http://www.vim.org/tips/tip.php?tip_id=305 Best of Vim Tips
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: More zsh tricks required please
2004-06-19 12:43 More zsh tricks required please zzapper
@ 2004-06-19 13:06 ` Christian Schneider
2004-06-20 12:19 ` Julius Plenz
2004-06-21 0:38 ` Drew Perttula
2 siblings, 0 replies; 10+ messages in thread
From: Christian Schneider @ 2004-06-19 13:06 UTC (permalink / raw)
To: zsh-users
* zzapper <david@tvis.co.uk> typed:
> I'm an intermediate zsh user, and can't do the whacko stuff yet.
> But haven't learnt any tricks recently, last one was
>
> > vim =some_script (from anywhere)
>
> where the = means search paths for script location.
>
> So please a link to a handy website, or your tips/tricks.
>
> On the above BTW is it possible to do a
>
> > cd =some_script (doesn't work)
>
> to jump to the directory??
| cd =some_script(:h)
I use a function for this:
| function dcd { cd =$1(:h) }
--
\\___// Mynd you, m00se bites
(o o) Kan be pretti nasti
--ooO-(_)-Ooo--------------------------------------------------
Christian 'strcat' Schneider <strcat@gmx.net>
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: More zsh tricks required please
2004-06-19 12:43 More zsh tricks required please zzapper
2004-06-19 13:06 ` Christian Schneider
@ 2004-06-20 12:19 ` Julius Plenz
2004-06-21 0:38 ` Drew Perttula
2 siblings, 0 replies; 10+ messages in thread
From: Julius Plenz @ 2004-06-20 12:19 UTC (permalink / raw)
To: zsh-users
* zzapper <david@tvis.co.uk> [2004-06-19 14:46]:
> I'm an intermediate zsh user, and can't do the whacko stuff yet.
> So please a link to a handy website, or your tips/tricks.
http://strcat.neessen.net/zsh.html
...or a german version with more "tricks":
http://michael-prokop.at/computer/tools_zsh.html
Julius
--
Julius Plenz, <jp@cvmx.de> Surf, Mail, Smile! www.cvmx.de/ <><
http://plenz.com/ Please don't Cc me in your replies, thanks
#129455376 3993 FD19 2AF0 E21E 5D74 E963 144C 5EE9 186D CA0D
gpg --verbose --keyserver subkeys.pgp.net --recv-key 0x186DCA0D
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: More zsh tricks required please
2004-06-19 12:43 More zsh tricks required please zzapper
2004-06-19 13:06 ` Christian Schneider
2004-06-20 12:19 ` Julius Plenz
@ 2004-06-21 0:38 ` Drew Perttula
2007-04-16 14:40 ` cd to a file Andy Spiegl
2 siblings, 1 reply; 10+ messages in thread
From: Drew Perttula @ 2004-06-21 0:38 UTC (permalink / raw)
To: zzapper; +Cc: zsh-users, drewp
> On the above BTW is it possible to do a
>
> > cd =some_script (doesn't work)
>
> to jump to the directory??
>
That works for me, thanks to this bit of .zshrc:
# cd to a file should take you to the dir that contains the file
# courtesy of Artur Penttinen <artur@niif.spb.su>
function cd () {
if [[ -f $1 ]]; then
builtin cd $1:h
else
builtin cd $1
fi
}
^ permalink raw reply [flat|nested] 10+ messages in thread
* cd to a file
2004-06-21 0:38 ` Drew Perttula
@ 2007-04-16 14:40 ` Andy Spiegl
2007-04-16 16:00 ` Frank Terbeck
0 siblings, 1 reply; 10+ messages in thread
From: Andy Spiegl @ 2007-04-16 14:40 UTC (permalink / raw)
To: zsh-users
Hi,
a long while ago Drew Perttula <drewp@dot.bigasterisk.com> posted this very
useful function:
> # cd to a file should take you to the dir that contains the file
> # courtesy of Artur Penttinen <artur@niif.spb.su>
> function cd () {
> if [[ -f $1 ]]; then
> builtin cd $1:h
> else
> builtin cd $1
> fi
> }
I just noticed that it breaks cd substitution (cd with 2 arguments)
and patched it like this:
# cd to a file should take you to the dir that contains the file
# courtesy of Artur Penttinen <artur@niif.spb.su>
function cd () {
if [[ -n $2 ]]; then
builtin cd $1 $2
elif [[ -f $1 ]]; then
builtin cd $1:h
else
builtin cd $*
fi
}
Could still be optimized though, I guess.
Andy.
--
Fotos: familie.spiegl.de Info: peru.spiegl.de
Weblog: blog.spiegl.de Mail: andy@spiegl.de
--
Finagle's Second Law:
No matter what the anticipated result, there will always be
someone eager to (a) misinterpret it, (b) fake it, or (c) believe
it happened according to his own pet theory.
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: cd to a file
2007-04-16 14:40 ` cd to a file Andy Spiegl
@ 2007-04-16 16:00 ` Frank Terbeck
2007-04-18 1:08 ` Andy Spiegl
2007-04-21 15:12 ` Atom Smasher
0 siblings, 2 replies; 10+ messages in thread
From: Frank Terbeck @ 2007-04-16 16:00 UTC (permalink / raw)
To: zsh-users
Andy Spiegl <zsh.Andy@spiegl.de>:
[...]
> # cd to a file should take you to the dir that contains the file
> # courtesy of Artur Penttinen <artur@niif.spb.su>
> function cd () {
> if [[ -n $2 ]]; then
> builtin cd $1 $2
> elif [[ -f $1 ]]; then
> builtin cd $1:h
> else
> builtin cd $*
> fi
> }
>
> Could still be optimized though, I guess.
I once did a 'cd'-wrapper function, that also tries to do some basic
error correction (this is also on <http://zshwiki.org>):
[snip]
function smart_cd () {
if [[ -f $1 ]] ; then
[[ ! -e ${1:h} ]] && return 1
print correcting ${1} to ${1:h}
builtin cd ${1:h}
else
builtin cd ${1}
fi
}
function cd () {
setopt localoptions
setopt extendedglob
local approx1 ; approx1=()
local approx2 ; approx2=()
if (( ${#*} == 0 )) || [[ ${1} = [+-]* ]] ; then
builtin cd "$@"
elif (( ${#*} == 1 )) ; then
approx1=( (#a1)${1}(N) )
approx2=( (#a2)${1}(N) )
if [[ -e ${1} ]] ; then
smart_cd ${1}
elif [[ ${#approx1} -eq 1 ]] ; then
print correcting ${1} to ${approx1[1]}
smart_cd ${approx1[1]}
elif [[ ${#approx2} -eq 1 ]] ; then
print correcting ${1} to ${approx2[1]}
smart_cd ${approx2[1]}
else
print couldn\'t correct ${1}
fi
elif (( ${#*} == 2 )) ; then
builtin cd $1 $2
else
print cd: too many arguments
fi
}
[snap]
Regards, Frank
--
In protocol design, perfection has been reached not when there is
nothing left to add, but when there is nothing left to take away.
-- RFC 1925
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: cd to a file
2007-04-16 16:00 ` Frank Terbeck
@ 2007-04-18 1:08 ` Andy Spiegl
2007-04-21 15:12 ` Atom Smasher
1 sibling, 0 replies; 10+ messages in thread
From: Andy Spiegl @ 2007-04-18 1:08 UTC (permalink / raw)
To: zsh-users
Hi Frank,
> I once did a 'cd'-wrapper function, that also tries to do some basic
> error correction (this is also on <http://zshwiki.org>):
Very nice and smarter than "my" version!
Thanks for sharing,
Andy.
--
There are only 10 types of people:
Those who understand binary and those who don't.
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: cd to a file
@ 2007-04-21 15:12 ` Atom Smasher
2007-04-22 18:18 ` Frank Terbeck
0 siblings, 1 reply; 10+ messages in thread
From: Atom Smasher @ 2007-04-21 15:12 UTC (permalink / raw)
To: zsh-users
not nearly as elaborate as Frank Terbeck's function, but i think this
provides the basic functionality to cd to a file without breaking
anything. the "echo" command is very much optional...
cd() {
## cd to a file
if [ 1 = "${#}" ] && [ '-' != "${1}" ] && [ \! -d "${1}" ] && [ -d "${1:h}" ]
then
echo "correcting \"${1}\" to \"${1:h}\"" >&2
builtin cd "${1:h}"
else
builtin cd "${@}"
fi
}
--
...atom
________________________
http://atom.smasher.org/
762A 3B98 A3C3 96C9 C6B7 582A B88D 52E4 D9F5 7808
-------------------------------------------------
"We must have strong minds, ready to accept facts as they are."
-- President Harry Truman
"I don't care what the facts are."
-- President George H.W. Bush, 1988
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: cd to a file
2007-04-21 15:12 ` Atom Smasher
@ 2007-04-22 18:18 ` Frank Terbeck
2007-04-23 8:45 ` Atom Smasher
0 siblings, 1 reply; 10+ messages in thread
From: Frank Terbeck @ 2007-04-22 18:18 UTC (permalink / raw)
To: zsh-users
Atom Smasher <atom@smasher.org>:
> not nearly as elaborate as Frank Terbeck's function, but i think this
> provides the basic functionality to cd to a file without breaking
> anything. the "echo" command is very much optional...
Hm, I actually think, that my wrapper works for most (all?) possible
invocations of the 'cd' builtin.
> cd() {
> ## cd to a file
> if [ 1 = "${#}" ] && [ '-' != "${1}" ] && [ \! -d "${1}" ] && [ -d "${1:h}" ]
> then
> echo "correcting \"${1}\" to \"${1:h}\"" >&2
> builtin cd "${1:h}"
> else
> builtin cd "${@}"
> fi
> }
This breaks things like 'cd -2', 'cd +2' or 'cd +'.
Regards, Frank
--
In protocol design, perfection has been reached not when there is
nothing left to add, but when there is nothing left to take away.
-- RFC 1925
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: cd to a file
2007-04-22 18:18 ` Frank Terbeck
@ 2007-04-23 8:45 ` Atom Smasher
0 siblings, 0 replies; 10+ messages in thread
From: Atom Smasher @ 2007-04-23 8:45 UTC (permalink / raw)
To: zsh-users
On Sun, 22 Apr 2007, Frank Terbeck wrote:
>> cd() {
>> ## cd to a file
>> if [ 1 = "${#}" ] && [ '-' != "${1}" ] && [ \! -d "${1}" ] && [ -d "${1:h}" ]
>> then
>> echo "correcting \"${1}\" to \"${1:h}\"" >&2
>> builtin cd "${1:h}"
>> else
>> builtin cd "${@}"
>> fi
>> }
>
> This breaks things like 'cd -2', 'cd +2' or 'cd +'.
==========================
i haven't used those... back to the drawing board...
--
...atom
________________________
http://atom.smasher.org/
762A 3B98 A3C3 96C9 C6B7 582A B88D 52E4 D9F5 7808
-------------------------------------------------
Democracy, n.:
A government of the masses. Authority derived
through mass meeting or any other form of direct expression.
Results in mobocracy. Attitude toward property is
communistic... negating property rights. Attitude toward
law is that the will of the majority shall regulate, whether
it is based upon deliberation or governed by passion,
prejudice, and impulse, without restraint or regard to
consequences. Result is demagogism, license, agitation,
discontent, anarchy.
-- U. S. Army Training Manual
No. 2000-25 (1928-1932), since withdrawn.
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2007-04-23 8:45 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-06-19 12:43 More zsh tricks required please zzapper
2004-06-19 13:06 ` Christian Schneider
2004-06-20 12:19 ` Julius Plenz
2004-06-21 0:38 ` Drew Perttula
2007-04-16 14:40 ` cd to a file Andy Spiegl
2007-04-16 16:00 ` Frank Terbeck
2007-04-18 1:08 ` Andy Spiegl
2007-04-21 15:12 ` Atom Smasher
2007-04-22 18:18 ` Frank Terbeck
2007-04-23 8:45 ` Atom Smasher
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).