Skip to content

tamada/sibling

Repository files navigation

sibling

build Coverage Status

codebeat badge Go Report Card

License Version

get next/previous sibling directory name.

🗣️ Description

When a directory has too may sub directories, we are tiresome to traverse whole of sub directories. Because, sometimes we lose where we are. Ideally, we move directory by specifying ‘next’ or ‘previous,' not directory name.

The command like following makes us tired 👎.

cd ../next_directory_name

We should type command like below 👍.

cdnext

For this, I implemented sibling.

🏃 Usage

get next/previous sibling directory name

Usage: sibling [FLAGs] [DIRs...]
FLAGS
    -a, --absolute      print the directory name in the absolute path
    -l, --list          list the sibling directories
    -p, --progress      print the progress traversing directories
    -P, --parent        print parent directory, when no more sibling directories
                        (available on no-console mode)
    -t, --type <TYPE>   specify the traversing type of siblings (default: next, 
                        available: next, previous, first, last and random)

    -h, --help          print this message
    -v, --version       print version
ARGUMENTS
    DIR                 specify the directory. If not specified, the current directory is used

sibling prints the next directory name with 0 status code. The next directory is decided by the traversing type. Available values are: next, previous, first, last and random, default is next.

After visiting the final directory, sibling prints nothing and exits with non-zero status code.

🆒 Utilities

The following utility functions are generated by executing sibling --init bash. Therefore, write the snippet (eval "$(sibling --init bash)") into your .bash_profile, and restart bash session.

🔡 change_directory_to_sibling

function __change_directory_to_sibling() {
    traversing_type="$1"
    if [ "$1" == "" ]; then
        traversing_type="next"
    fi
    next=$(sibling -t $traversing_type)
    status=$?
    if [ $status -ne 0 ] ; then
        echo "done ($(sibling -p -t $traversing_type))"
        cd ..
    else
        cd $next
        echo "$PWD ($(sibling -p -t $traversing_type))"
    fi
    return $status
}

cdnext

function cdnext() {
    __change_directory_to_sibling next
}

cdprev

function cdprev() {
    __change_directory_to_sibling previous
}

🔁 cdrand

function cdrand() {
    __change_directory_to_sibling random
}

⚓ Installation

🍺 Homebrew

Install sibling via Homebrew, simply run:

brew tap tamada/brew
brew install sibling

Go lang

Install by CLI, run:

go get github.com/tamada/sibling

💪 Compiling yourself

Get source codes by git clone or download from GitHub, then run make to build sibling

$ git clone https://github.com/tamada/sibling.git # or download from https://github.com/tamada/sibling
$ cd sibling
$ make

💼 Requirements

Development

  • Go lang 1.17 and after
  • Dependencies (See go.mod)
    • github.com/spf13/cobra v1.2.1

😄 About the project

📜 License

  • WTFPL
    • 👍 Commercial use
    • 👍 Modification
    • 👍 Distribution
    • 👍 Private use

👨‍💼 Developers 👩‍💼