You are not logged in.

#1 2022-01-30 08:15:24

SudeepSharma100
Member
Registered: 2021-10-23
Posts: 6

How to use parameters in zsh alias.

Is it possible to use one alias command and use parameters to perform multiple tasks?
For example:

If I do cddoc then it should cd in ~/Documents.
But if I do cddoc -s (or any parameter) then it should cd in another folder inside ~/Documents such as ~/Documents/anyfolder.

I can't figure out how to create and make the parameters work.

Offline

#2 2022-01-30 08:35:04

dogknowsnx
Guest

Re: How to use parameters in zsh alias.

Why do you wanna use " -" by any means? Simply use "cddocs".

Last edited by dogknowsnx (2022-01-30 08:35:25)

#3 2022-01-30 08:42:20

SudeepSharma100
Member
Registered: 2021-10-23
Posts: 6

Re: How to use parameters in zsh alias.

dogknowsnx wrote:

Why do you wanna use " -" by any means? Simply use "cddocs".

Ok I did: cddoc s
But it gave me error: cd: string not in pwd: (folder location)

Location is correct and there is folder located in the location.

Last edited by SudeepSharma100 (2022-01-30 08:42:46)

Offline

#4 2022-01-30 08:45:24

dogknowsnx
Guest

Re: How to use parameters in zsh alias.

Free your mind from "must have empty space in my command"...

#5 2022-01-30 09:03:15

arch_jsb
Member
Registered: 2010-03-13
Posts: 30

Re: How to use parameters in zsh alias.

SudeepSharma100 wrote:

Is it possible to use one alias command and use parameters to perform multiple tasks?
For example:

If I do cddoc then it should cd in ~/Documents.
But if I do cddoc -s (or any parameter) then it should cd in another folder inside ~/Documents such as ~/Documents/anyfolder.

I can't figure out how to create and make the parameters work.

in .zshrc, you can put:
aaa=/root/Documents
.....
then once zsh is reloaded, a simple
cd $aaa is less than a two-paramater alias.
[ best to be sure aaa is not any comand yet...]

better yet, one can then do such tricks as:
cp -iv file.txt $aaa
saving a whole bunch of keystrokes.

Last edited by arch_jsb (2022-01-30 09:04:43)

Offline

#6 2022-01-30 09:08:32

dogknowsnx
Guest

Re: How to use parameters in zsh alias.

Why bloat your .zshrc to make it look like you're using parameters? I don't get it...

EDIT: You can install and source "zsh-autosuggestions" Simply use zsh's built-in completion in order to save keystrokes for any location, not just predefined ones.

Last edited by dogknowsnx (2022-01-30 09:25:46)

#7 2022-01-30 09:21:25

tucuxi
Member
From: Switzerland
Registered: 2020-03-08
Posts: 291

Re: How to use parameters in zsh alias.

Use a function instead of an alias.

Offline

#8 2022-01-30 09:35:48

seth
Member
From: Won't reply 2 private help req
Registered: 2012-09-03
Posts: 77,091

Re: How to use parameters in zsh alias.

tucuxi wrote:

Use a function instead of an alias.

+1
In this very case you could use an ugly hack to cheat zsh:

alias cddoc='HOME=/home/<username>/Documents cd; HOME=/home/<username>/Documents cd'

Offline

Board footer

Powered by FluxBB