Code Monkey home page Code Monkey logo

bd's Introduction

bd

Description

Quickly go back to a specific parent directory in bash instead of typing "cd ../../.." redundantly.


Installation

For OS X/macOS

Using MacPorts:

sudo port install bd

For Debian/Ubuntu

Packages available here:

https://tracker.debian.org/pkg/bd

https://launchpad.net/ubuntu/+source/bd

For Arch Linux

AUR packages available here:

https://aur.archlinux.org/packages/bd

https://aur.archlinux.org/packages/bd-git

For other OS

wget --no-check-certificate -O /usr/local/bin/bd https://raw.github.com/vigneshwaranr/bd/master/bd
chmod +rx /usr/local/bin/bd
echo 'alias bd=". bd -si"' >> ~/.bashrc
source ~/.bashrc

# If you need autocomplete support, follow these two steps
wget -O /etc/bash_completion.d/bd https://raw.github.com/vigneshwaranr/bd/master/bash_completion.d/bd
source /etc/bash_completion.d/bd

To enable case-sensitive directory name matching, use -s instead of -si in the alias.


How to use:

If you are in this path /home/user/project/src/org/main/site/utils/file/reader/whatever and you want to go to site directory quickly,

then just type: bd site

In fact, You can simply type bd <starting few letters> like bd s or bd si

If there are more than one directories with same name up in the hierarchy, bd will take you to the closest. (Not considering the immediate parent.)


Other uses:

Using bd within backticks (`bd <letter(s)>`) prints out the path without changing the current directory.

You can take advantage of that by combining `bd <letter(s)>` with other commands such as ls, ln, echo, zip, tar etc..

Example:

  1. If you just want to list the contents of a parent directory, without going there, then you can use: ls `bd p` in the given example, it will list the contents of /home/user/project/

  2. If you want to execute a file somewhere in a parent directory, `bd p`/build.sh will execute /home/user/project/build.sh while not changing the current directory.

  3. If you reside in /home/user/project/src/org/main/site/utils/file/reader/whatever and want to change to /home/user/project/test, then try cd `bd p`/test


Screenshot: bd screenshot


Thanks:


See also:

bd's People

Contributors

antiz96 avatar christiansilvermoon avatar cqr avatar janosgyerik avatar jaysh avatar jophinep avatar peterwvj avatar riklund avatar rmhsilva avatar vigneshwaran-raveendran avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

bd's Issues

OS X/BSD issues

I really love the idea behind bd, and it comes in handy a lot for me.

Just to let you know, there are some inconsistencies with the way that OS X (BSD's) sed and other tools work vs. GNU. For instance, the "I" flag on the regex for case sensitivity doesn't work, and in the completion file the sed substitution fails for reasons I don't understand. I was able to fix completion by using tr instead of sed:

 pwd | tr / "\n"

I ended up redoing it completely, though, and now there's case insensitive completion and replacement, at least on Darwin with Bash 4.3.11.

I spent a long time early this morning trying to figure out a case insensitive way to make the main script work before I realized you had already updated it. Unfortunately, your solution is one of the first ones I had to discard. I could install the GNU utils, but I'd like to think there's a solution for the OS X crowd.

I did give up and write my own version of this utility. It's simpler, but it's suiting my needs. It assumes you always want partial matching and doesn't take all of your logic into account. It uses Ruby to handle the string parsing. A scripting language like Ruby or Perl was the only way I could get it to work for me after spending an hour wrangling around with sed and awk. Just sharing it in case you can gleam anything from it.

Sort bash completions in dir nesting order

Currently completions are ordered alphabetically. Would be nice if there were an option to sort them in the order in which they appear in the path -- so if current working dir is /home/user/Desktop/stuff/, then autocomplete would go:

$ bd <tab-key><tab-key>
home user Desktop

cd `bd p` from the examples does not work for me

bd works fine for me on debian unstable other than cd bd p from the examples. It gives me this error:
devil@siductionbox:~/work/Linux-User/CD-Helferlein/Screenies$ cd bd p /Todo
(where ToDo is a sub-dir of work)
bash: cd: Zu viele Argumente.
which translates to:
bash: cd: too many arguments

Any idea what might be the reason for that?
Let me know if you need any more info

Problems with zsh

I tried bd in zsh.
So instead of adding the alias to the .bashrc file, I add it to my .zshrc file
Then I sourced it.
And when i tried to use bd, instead of changing the directory
I'm still in the same directory, and the name has changed, and it's : NEWPWD

Installed from Debian Repo and it does not work

I have installed bd from debian repo and it doesnt work

pic.

if I installed form debian repo, I think I didn't need to add aliases (. bd -si) and I have source the bash file and restarting my terminal, but still doesnt work.

What does `bd` without parameters?

What is the effect of bd (without any parameters)?

In most cases it does cd .., wich I like!

But consider this:

$ pwd
/home
$ bd
/home
$ pwd
/home

Expected: cd to /

Autocomplete

Would be very helpful unfortunately I have no experience in writing them

Need auto updating

Should support updating bd by itself or by passing a param

  • Invoking 'bd -update' should update itself
  • Should figure out itself if new updates are available in github and notify the user to update.

Bash completion doesn't work on Mac OSX

There is a problem with the sed implementation not handling newlines in replacement strings, and this was causing problems with the bash completion script on the platform.

I have implemented a fix that seems to work on both Mac and Linux, but I have only tested CentOS on the Linux side, so someone may want to do more testing.

Fix is in #33

bd for macOS

Since the updates/acitivity here seems a bit low frequent, I make an issue istead of a PR. (Don't want a fork hanging around for too long.)

If you want, you can update your ReadMe with:

***For OS X/macOS***

Using [MacPorts](https://ports.macports.org/port/bd):

```bash
sudo port install bd
```

For OS X/macOS

Using MacPorts:

sudo port install bd

Suggestion: Make the -s option activated by default

Hi,

This script is great and I'd like to see it included in the GNU tools ^^

Just a little suggestion, make the -s option activated by default to avoid the alias in .bashrc. And add a "-S" option for "strict search"

This is just a suggestion. You are free to reject it.

bd to / throws error

bd to / throws following error:

No such occurrence.
/home/jophine/ctf-chef/linkedapp
terminal_021


bd does not jump

Hi,
I installed bd on Ubuntu 22.04, completely. But when input "bd xxx", it did not jump to the xxx folder, only display the xxx forder info.
Like this,
zhi@:~/workspace/uuu_fw/user/uww/uwwc$ bd user
/home/zhi/workspace/uuu_fw/user/

add mode for tracking previous CWDs

Hey.

The current feature of bd is to allow one to go back to any parent dir above the current working directory.

I'd propose another respectively additional mode:

  • bd keeps a (configurable) array of last current working directories
  • since it's anyway bash, it could be easily added to the PROMPT_COMMAND and from there read PWD, respectively add it to some array (which should get some name, that hopefully nothing else uses (e.g. BASH_BD_PWD_RRDB or something better ;-) ) .
  • the array would be a round robin array, so once it's longer than it's maximum lenght, the first element is unset, the indexing can be gotten back to by assigning the array to itself.
  • if a PWD is to be added it's checked whether it's already in the array, if so, it's just moved to the end (similarly by unsetting the old one, "re-indexing" the array and then adding it newly (not doing this, if it was the last element)
  • one could make a mode, in which the PWD is resolved to the realpath (i.e. resolving symlinks)
  • the last dir, which is the current working dir, wouldn't be shown by the tool

The interface could be as follows:

  • either a new tool, which when completing shows the array index + path, one per line
  • the number would then be use to select the desired entry and bd would cd to it
    or:
  • one could integrate it directly into bd
  • since the numbers might be directories in the path (and could therefore overlap with the current functionality) the index number would need to be used with a leading / which cannot appear in the current arguments to it anyway

e.g.:

/home/foo/test/bar$ bd<tab>
0: /usr
1: /home/foo/test
2: /proc/2343/fd
home foo test
$

So the last line is what we have currently.

The other lines are the previous current working dirs.

If one now enters e.g. bd /0 it would cd to /usr and then the list would look like:

0: /home/foo/test
1: /proc/2343/fd
2: /home/foo/test/bar

(and 0: /usr would be hidden in the array already)

Another config option could allow to hide out any dirs in the list, which are parents of the current dir, since these are already quickly reachable via the last line, e.g. above:

/home/foo/test/bar$ bd<tab>
0: /usr
2: /proc/2343/fd
home foo test
$

1: /home/foo/test wouldn't be printed, because it's already reachable via the test.

Of course it cannot be deleted from the array, because if one moves to another dir, it would be needed again.

And just bd could be made a shortcut for going to the last one in the list, so consecutive calls of just bd should switch back and forth between the previous and current dir.

What do you think? ;-)

Cheers,
Chris.

bd is not working in fish shell

It just echos out the present working directory. Tried it in bash shell works perfectly. sourced the config.fish file by inserting this line too alias bd=". bd -si" throws this error
.: Error encountered while sourcing file “bd”: .: No such file or directory

bd not working #Ubuntu16.04

I can't quite get this "bd" thing going, what wrong did I do, see code...

ousodanos@ousodanos-UX360CA:/usr/bin$ chmod +rx bd
chmod: changing permissions of 'bd': Operation not permitted
ousodanos@ousodanos-UX360CA:/usr/bin$ sudo chmod +rx bd
ousodanos@ousodanos-UX360CA:/usr/bin$ sudo echo 'alias bd=". bd -s"' >> /.bashrc
ousodanos@ousodanos-UX360CA:/usr/bin$ source /.bashrc
ousodanos@ousodanos-UX360CA:/usr/bin$ cd
ousodanos@ousodanos-UX360CA:
$ sudo wget -o /etc/bash_completion.d/bd https://raw.github.com/vigneshwaranr/bd/master/bash_completion.d/bd
ousodanos@ousodanos-UX360CA:
$ sudo source /etc/bash_completion.d/bd
sudo: source: command not found
ousodanos@ousodanos-UX360CA:$ source /etc/bash_completion.d/bd
--2017-04-15: command not found
bash: /etc/bash_completion.d/bd: line 2: syntax error near unexpected token (' bash: /etc/bash_completion.d/bd: line 2: Resolving raw.github.com (raw.github.com)... 151.101.172.133'
ousodanos@ousodanos-UX360CA:
$ cd Downloads/LibreOffice_5.3.2.2_Linux_x86-64_deb/DEBS/
ousodanos@ousodanos-UX360CA:/Downloads/LibreOffice_5.3.2.2_Linux_x86-64_deb/DEBS$ bd Downloads
--2017-04-15: command not found
bash: /usr/bin/bd: line 2: syntax error near unexpected token (' bash: /usr/bin/bd: line 2: Resolving raw.github.com (raw.github.com)... 151.101.172.133'
ousodanos@ousodanos-UX360CA:
/Downloads/LibreOffice_5.3.2.2_Linux_x86-64_deb/DEBS$

I'd really appreciate a quick response here, thanks

Provide man page

The convention is to have one. Also, as soon as one has an alias, bd -h won't print the help.

For the man page, the default output of bd would need to be reformatted to meet the conventions.

See https://github.com/clvv/fasd for an example of how to create a man page from a Markdown master using Pandoc.

Has This Been Abandoned?

I couldn't help but notice this repo seems not to have had any commits in over a year, and there are Pull Requests such as #20 that have seemingly not been acknowledged in 8 years as well as open issues such as #15 dating back 9 years.

The latest release 1.02, is now 6 years old.

The script does work as is, but could be improved, along with better usage documentation.

bd not changing directorys as expected on ubuntu 19.04

bd folder name does only echo the target directory but does not actually switch to it.

I am using ubuntu 19.10 and fish 3.0.2, the same problem does exist in bash. Is there something to make it change the directory instead of just printing the target directory?

Add a silent flag

I know this is really minor (and possibly not worth a commit), but my OCD finds it very repetitive that bd echos the name of the new PWD since it's already in my $PS1. It would be nice if there was a -q (quiet) flag that could be added to suppress this echo.

I know that you can just comment out or remove the line, so perhaps this is a frivolous issue, but this would make the update process easier in my opinion (fetch from git instead of fetch and them comment out echo line).

Match substring

Wouldn't it be great if bd could also match substring at any potion?

Use case:

pwd
~/some-repo.git/3rdparty/component/src/include
bd git
pwd
~/some-repo.git

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.