Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simple maintenance improvements #46

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ To enable case-sensitive directory name matching, use `-s` instead of `-si` in t
**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,
and you want to go to `site` directory quickly,

then just type:
`bd site`
Expand All @@ -67,7 +67,7 @@ You can take advantage of that by combining <code>\`bd \<letter(s)\>\`</code> wi
1. If you just want to list the contents of a parent directory,
without going there, then you can use:
<code>ls \`bd p\`</code>
in the given example, it will list the contents of
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,
Expand Down Expand Up @@ -100,4 +100,4 @@ You can take advantage of that by combining <code>\`bd \<letter(s)\>\`</code> wi
* [0rax/fish-bd](https://github.com/0rax/fish-bd) - bd for [fish](http://fishshell.com/) shell
* [rvraghav93/win-bd](https://github.com/rvraghav93/win-bd) - bd for command prompt
* [peterwvj/eshell-up](https://github.com/peterwvj/eshell-up) - bd inspired command for Emacs' eshell
* [alebcay/awesome-shell](https://github.com/alebcay/awesome-shell) - A curated list of awesome command-line frameworks, toolkits, guides and gizmos
* [alebcay/awesome-shell](https://github.com/alebcay/awesome-shell) - A curated list of awesome command-line frameworks, toolkits, guides and gizmos
5 changes: 2 additions & 3 deletions bash_completion.d/bd
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
#!/bin/bash
# Add autocomplete support for bd for bash.
_bd()
{
# Handle spaces in filenames by setting the delimeter to be a newline.
# Handle spaces in filenames by setting the delimiter to be a newline.
local IFS=$'\n'
# Current argument on the command line.
local cur=${COMP_WORDS[COMP_CWORD]}
# Available directories to autcomplete to.
local completions=$( dirname `pwd` | sed 's|/|\'$'\n|g' )
local completions=$( dirname "$(pwd)" | sed 's|/|\'$'\n|g' )

COMPREPLY=( $(compgen -W "$completions" -- $cur) )
}
Expand Down
27 changes: 12 additions & 15 deletions bd
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#! /bin/bash
#!/usr/bin/env bash
help_msg () {
printf "Usage: bd [OPTION]... [PATTERN]\n"
printf "Quickly go back to a specific parent directory in bash.\n\n"

printf "\e[1mOPTIONS\e[0m\n"
printf " %-28s %s\n" "-s" "PATTERN can match part of directory name"
printf " %-28s %s\n" "-si" "PATTERN is Case Insensitve and can be partial"
printf " %-28s %s\n" "-si" "PATTERN is Case Insensitive and can be partial"
printf " %-28s %s\n" "-?, --help" "Display this message"

printf "\n\e[1mALTERNATE USAGE EXAMPLES\e[0m\n"
Expand All @@ -14,7 +14,7 @@ help_msg () {
return 0
}

usage_error () {
usage_error() {
cat << EOF
------------------------------------------------------------------
Name: bd
Expand All @@ -37,38 +37,35 @@ newpwd() {
case "$2" in
-s)
pattern=$3
NEWPWD=$(echo $oldpwd | sed 's|\(.*/'$pattern'[^/]*/\).*|\1|')
NEWPWD=$(echo "$oldpwd" | sed 's|\(.*/'$pattern'[^/]*/\).*|\1|')
;;
-si)
pattern=$3
NEWPWD=$(echo $oldpwd | perl -pe 's|(.*/'$pattern'[^/]*/).*|$1|i')
NEWPWD=$(echo "$oldpwd" | perl -pe 's|(.*/'$pattern'[^/]*/).*|$1|i')
;;
-?|--help)
help_msg
;;
*)
pattern=$2
NEWPWD=$(echo $oldpwd | sed 's|\(.*/'$pattern'/\).*|\1|')
NEWPWD=$(echo "$oldpwd" | sed 's|\(.*/'$pattern'/\).*|\1|')
esac
}

if [ $# -eq 0 ]
then
if [ $# -eq 0 ]; then
usage_error
elif [ "${@: -1}" = -v ]
then
elif [ "${@: -1}" = "-v" ]; then
usage_error
else
oldpwd=$(pwd)

newpwd "$oldpwd" "$@"

if [ "$NEWPWD" = "$oldpwd" ]
then

if [ "$NEWPWD" = "$oldpwd" ]; then
echo "No such occurrence."
else
echo $NEWPWD
cd "$NEWPWD"
echo "$NEWPWD"
cd -- "$NEWPWD"
fi
unset NEWPWD
fi
6 changes: 3 additions & 3 deletions run-tests.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash
#!/usr/bin/env bash

# make sure we're in the project directory
cd $(dirname "$0")
cd -- "$(dirname "$0")"

# just to include the functions defined in ./bd
. ./bd /dev/null > /dev/null
Expand All @@ -18,7 +18,7 @@ assertEquals() {
((total++))
expected=$1
actual=$2
if [[ $expected = $actual ]]; then
if [[ $expected == "$actual" ]]; then
((success++))
else
((failure++))
Expand Down