DEV Community

Cover image for Got Tired of Typing Directories with the cd Command, So I Made It Easier with a Shell Script
Kenta Takeuchi
Kenta Takeuchi

Posted on • Originally published at bmf-tech.com

Got Tired of Typing Directories with the cd Command, So I Made It Easier with a Shell Script

This article was originally published on bmf-tech.com.

Overview

I started feeling lazy about typing paths and directories like cd hogehoge, so I used a shell script to make it a bit easier.

Source

#!/bin/sh

# cd by selecting numbers
function cdSelect() {
        dirs=`ls -a`

        PS3="Select directory > "
        echo 'Directory list:'

        select dir in ${dirs}
        do
                stty erase ^H
                cd ${dir}
                break
        done
}
alias cd-s=cdSelect
Enter fullscreen mode Exit fullscreen mode

When you type cd-s, it looks like this:

Directory list:

1) .
2) ..
3) hoge_a
4) hoge_b
5) hoge_c

Select directory > 3
Enter fullscreen mode Exit fullscreen mode

Thoughts

It might be challenging when there are many directories, but it has reduced the stress of using the cd command. I'm considering making a vim version too.

Top comments (0)