You are not logged in.

#1 2011-09-27 08:58:52

orschiro
Member
Registered: 2009-06-04
Posts: 2,136
Website

use file path alias in cd

Hello guys,

I have an alias alias personal='cd /media/personal/files/' but I would love to use this inside other bash commands such as cd.

For example:

cd personal/music
rm personal/doc/file.txt

This would be really dreamlike. Is something like that achievable with bash?

Regards

Last edited by orschiro (2011-09-27 08:59:21)

Offline

#2 2011-09-27 09:34:29

bohoomil
Member
Registered: 2010-09-04
Posts: 2,376
Website

Re: use file path alias in cd

I may be wrong, but AFAIK it's not. Aliases point to commands, while cd-ing can affect only dirs.

Edit: Wouldn't a symlink be enough here?

Last edited by bohoomil (2011-09-27 09:35:25)


:: Registered Linux User No. 223384

:: github
:: infinality-bundle+fonts: good looking fonts made easy

Offline

#3 2011-09-27 09:35:55

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: use file path alias in cd

In bash you can put e.g.

shopt -s cdable_vars
export apps="/home/karol/test/apps"
export usb="/media/usb"
export cachedir="/var/cache/pacman/pkg"

in your ~/.bashrc and then

[karol@black ~]$ cd apps
/home/karol/test/apps
[karol@black apps]$ 

Offline

#4 2011-09-27 10:21:04

orschiro
Member
Registered: 2009-06-04
Posts: 2,136
Website

Re: use file path alias in cd

I'm not quite sure if this solves my problem.

[bashrc]
shopt -s cdable_vars
export personal="/media/personal/robert"

Let's assume I want to open a folder 'share' in personal.

I would do 'cd personal/share' but bash cannot find the directory.

Last edited by orschiro (2011-09-27 10:21:39)

Offline

#5 2011-09-27 10:26:33

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: use file path alias in cd

In ~/.bashrc set

test="/home/karol/test"

then

[karol@black ~]$ echo $test
/home/karol/test
[karol@black ~]$ cd $test/apps
[karol@black apps]$ 

Offline

#6 2011-09-27 10:42:14

orschiro
Member
Registered: 2009-06-04
Posts: 2,136
Website

Re: use file path alias in cd

That works better. Thank you.

However, I guess completion and using test instead of variable $test is impossible?

Offline

#7 2011-09-27 10:45:59

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: use file path alias in cd

'test' is just a variable, you need to call it like any other variable -'$test'.
I've heard that zsh is the ultimate interactive shell, you may want to try it out.

Offline

Board footer

Powered by FluxBB