You are not logged in.

#1 2014-03-13 21:54:45

hrdx
Member
Registered: 2014-03-11
Posts: 5

cd into folders automagically?

Is it possible to make bash treat typing in a folder name as cd + this folder name? I type cd all the time and it's sort of tiring. Also it would be nice to make bash also automatically xdg-open file names which are typed in, but are not folders.

Thanks.

Offline

#2 2014-03-13 21:58:41

WorMzy
Forum Moderator
From: Scotland
Registered: 2010-06-16
Posts: 5,540

Re: cd into folders automagically?

Not sure about bash, but zsh has an option for this. It's called autocd.

EDIT: https://www.gnu.org/software/bash/manua … iltin.html

Last edited by WorMzy (2014-03-13 21:59:41)


Sakura:-
Mobo: ASUS P8Z77-V PRO // Processor: Intel Core i7-3770K 3.4GHz // GFX: nVidia GeForce GTX 970 Ti // RAM: 32GB (4x 8GB) Corsair DDR3 (@ 2133MHz) // Storage: 1x 3TB Seagate SATAII 5x 1TB Samsung SATAII, 2x 120GB Corsair SSD

Offline

#3 2014-03-13 21:59:32

Awebb
Member
Registered: 2010-05-06
Posts: 4,528

Re: cd into folders automagically?

And then I create a file or folder with the same name as an executable and the joke is on you.

Offline

#4 2014-03-13 22:01:15

WorMzy
Forum Moderator
From: Scotland
Registered: 2010-06-16
Posts: 5,540

Re: cd into folders automagically?

Awebb wrote:

And then I create a file or folder with the same name as an executable and the joke is on you.

Make a folder called cd. tongue


Sakura:-
Mobo: ASUS P8Z77-V PRO // Processor: Intel Core i7-3770K 3.4GHz // GFX: nVidia GeForce GTX 970 Ti // RAM: 32GB (4x 8GB) Corsair DDR3 (@ 2133MHz) // Storage: 1x 3TB Seagate SATAII 5x 1TB Samsung SATAII, 2x 120GB Corsair SSD

Offline

#5 2014-03-13 22:06:19

hrdx
Member
Registered: 2014-03-11
Posts: 5

Re: cd into folders automagically?

Awebb wrote:

And then I create a file or folder with the same name as an executable and the joke is on you.

You still need dot slash to launch a local executable, so i don't think those two would collide - besides, i can't remember naming folders "sudo" or "rm". But it's a valid point.

WorMzy wrote:

Not sure about bash, but zsh has an option for this. It's called autocd.

EDIT: https://www.gnu.org/software/bash/manua … iltin.html

Thanks, it seems to be built in after all.

shopt -s autocd

Checking this out right now, kind of buggy imho - for example bash autocompletion doesn't always kick in without cd - it seems to work ok if a folder name is capitalized. Oh, well..

Last edited by hrdx (2014-03-13 22:12:38)

Offline

#6 2014-03-13 22:38:42

Rasi
Member
From: Germany
Registered: 2007-08-14
Posts: 1,856
Website

Re: cd into folders automagically?

Awebb wrote:

And then I create a file or folder with the same name as an executable and the joke is on you.

i should try this...

Last edited by Rasi (2014-03-13 22:39:38)


He hoped and prayed that there wasn't an afterlife. Then he realized there was a contradiction involved here and merely hoped that there wasn't an afterlife.

Douglas Adams

Offline

#7 2014-03-14 05:42:42

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

Re: cd into folders automagically?

I have

shopt -s cdable_vars

export apps="/home/karol/apps"
export usb="/media/usb"
export cachedir="/var/cache/pacman/pkg"
export foo="/home/karol/test/foo"
export bar="/home/karol/test/bar"

in my .bashrc.

$ pwd
/home/karol/test
$ cd cachedir
/var/cache/pacman/pkg
$ pwd
/var/cache/pacman/pkg
$ cd foo
/home/karol/test/foo
$ pwd
/home/karol/test/foo

Offline

#8 2014-03-14 06:04:27

x33a
Forum Moderator
Registered: 2009-08-15
Posts: 3,424
Website

Re: cd into folders automagically?

hrdx wrote:

Checking this out right now, kind of buggy imho - for example bash autocompletion doesn't always kick in without cd - it seems to work ok if a folder name is capitalized. Oh, well..

Prepend

./

before the foldernames, and the completion should work fine.

Offline

#9 2014-03-14 08:08:43

Awebb
Member
Registered: 2010-05-06
Posts: 4,528

Re: cd into folders automagically?

I think cd is easier to type than ./.

Offline

#10 2014-03-14 09:55:56

x33a
Forum Moderator
Registered: 2009-08-15
Posts: 3,424
Website

Re: cd into folders automagically?

you need to type an extra character (space) with cd tongue

Offline

#11 2014-07-11 20:14:06

rwd
Member
Registered: 2009-02-08
Posts: 646

Re: cd into folders automagically?

If you want to navigate through folders with as little typing as possible try 'autojump' from the community repos. See how it works here:
https://www.youtube.com/watch?v=tnNyoMGnbKg

Offline

#12 2014-07-11 20:54:47

HiImTye
Member
From: Nanaimo, BC, Canada
Registered: 2012-05-09
Posts: 403

Re: cd into folders automagically?

you could make aliases

alias Home='cd "$HOME"'
alias Pictures='cd "$HOME/Pictures"'
# etc..

also, if you want to 'cd "$HOME"' then you can just 'cd' and it assumes you want to go to ~

Last edited by HiImTye (2014-07-11 20:55:28)

Offline

#13 2014-07-11 21:09:00

rgb-one
Member
Registered: 2013-09-15
Posts: 19

Re: cd into folders automagically?

Ranger File Manager has some useful shortcuts for navigating to directories. you can set aliases to go to the most frequently visited directories or for all the directories in /

eg.
alias gh='cd $HOME'
alias ge='cd /etc/'
alias gu='cd /usr/'

etc.

Offline

#14 2014-07-11 21:14:25

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

Re: cd into folders automagically?

Isn't 'cd $HOME' the same as 'cd'?

See also the aforementioned 'shopt -s autocd' and 'shopt -s cdable_vars'.

Last edited by karol (2014-07-11 21:15:12)

Offline

#15 2014-07-11 21:42:02

chaonaut
Member
From: Kyiv, Ukraine
Registered: 2014-02-05
Posts: 317

Re: cd into folders automagically?

setting $CDPATH does that.

$ echo $CDPATH
/home/chaonaut/chaos:/home/chaos
$ pwd
/home/chaonaut
$ cd Ozric\ Tentacles
/home/chaos/Ozric Tentacles
$ pwd
/home/chaos/Ozric Tentacles

— love is the law, love under wheel, — said aleister crowley and typed in his terminal:
usermod -a -G wheel love

Offline

Board footer

Powered by FluxBB