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

Add sort feature: goto --list --sort #67

Open
wants to merge 1 commit 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
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,14 +148,24 @@ Pressing the `tab` key after the command (`-u` or `--unregister`), the completio
### List aliases

To get the list of your currently registered aliases, use:

```bash
goto -l
```

or

```bash
goto --list
```

or

```bash
goto -l --sort # or
goto --list --sort # sort output
```

### Expand an alias

To expand an alias to its value, use:
Expand Down
17 changes: 13 additions & 4 deletions goto.sh
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ goto()
_goto_directory_pop
;;
-l|--list)
_goto_list_aliases
_goto_list_aliases "$@"
;;
-x|--expand) # Expand an alias
_goto_expand_alias "$@"
Expand Down Expand Up @@ -87,7 +87,7 @@ _goto_resolve_db()
_goto_usage()
{
cat <<\USAGE
usage: goto [<option>] <alias> [<directory>]
usage: goto [<option> <option>] <alias> [<directory>]

default usage:
goto <alias> - changes to the directory registered for the given alias
Expand All @@ -103,6 +103,7 @@ OPTIONS:
goto -o|--pop
-l, --list: lists aliases
goto -l|--list
goto -l|--list --sort
-x, --expand: expands an alias
goto -x|--expand <alias>
-c, --cleanup: cleans up non existent directory aliases
Expand All @@ -111,6 +112,11 @@ OPTIONS:
goto -h|--help
-v, --version: displays the version of the goto script
goto -v|--version

EXTRAS:
--sort: sorts output
goto -l --sort
goto --list --sort
USAGE
}

Expand Down Expand Up @@ -139,9 +145,12 @@ _goto_list_aliases()
local maxlength=$length
fi
done < "$GOTO_DB"

line_delimeter=$(printf "${GOTO_DELIMETER_CHAR:-.}%.0s" $(eval echo {1..${maxlength}}))
while read -r name directory; do
printf "\e[1;36m%${maxlength}s \e[0m%s\n" "$name" "$directory"
done < "$GOTO_DB"
# printf "\e[1;36m%${maxlength}s \e[0m%s\n" "$name" "$directory"
printf '\e[1;36m%s\e[0m %s %s\n' "${name}" "${line_delimeter:${#name}}" "$directory"
done < "$GOTO_DB" | if [ ! -z "${1}" ] && [ "${1}" == "--sort" ] ; then sort; else cat; fi
else
echo "You haven't configured any directory aliases yet."
fi
Expand Down