You are not logged in.

#1 2017-04-13 10:00:03

arch_apo
Member
Registered: 2017-04-13
Posts: 2

zshrc find alias error

Hello,
I want to make a simple alias for find. I want it to print me a message before find is ran. This the alias (function) I have currently in my .zsrhc:

find() {
        echo -e "[${red}+${normal}] ${green}locate${normal} is a much faster alternative to find."
        find $@
}

When I run find I get:

apg:~/ $ find -name "python"                                                                                                                       [10:58:36]
[+] locate is a much faster alternative to find.
[+] locate is a much faster alternative to find.
[+] locate is a much faster alternative to find.
.......
......
[+] locate is a much faster alternative to find.
find:2: maximum nested function level reached

Any ideas how to implement it? I want the output to be

[+] locate is a much faster alternative to find.
FIND RUNS HERE AS NORMAL

Thansk a lot!

Last edited by arch_apo (2017-04-13 10:09:34)

Offline

#2 2017-04-13 10:09:02

arch_apo
Member
Registered: 2017-04-13
Posts: 2

Re: zshrc find alias error

Ok I fixed it... Just in case someone has a similar problem...
Instead of find $@ do, /usr/bin/find $@ to avoid running the function recursively.

Offline

#3 2017-04-13 10:14:18

Slithery
Administrator
From: Norfolk, UK
Registered: 2013-12-01
Posts: 5,776

Re: zshrc find alias error

Your problem is that the function is calling itself over and over.

Either get it to call find directly instead of itself...

find() {
        echo -e "[${red}+${normal}] ${green}locate${normal} is a much faster alternative to find."
        /usr/bin/find $@
}

Or just use an alias...

alias find='echo -e "[${red}+${normal}] ${green}locate${normal} is a much faster alternative to find."; find'

No, it didn't "fix" anything. It just shifted the brokeness one space to the right. - jasonwryan
Closing -- for deletion; Banning -- for muppetry. - jasonwryan

aur - dotfiles

Offline

Board footer

Powered by FluxBB