Skip to content
Merged
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: 6 additions & 0 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,12 @@ Running `fresh edit` will open your `~/.freshrc` in your default `$EDITOR`.
`fresh show` will output each line of your `~/.freshrc` along with
every source file those lines match. Handy for auditing.

### Subcommands

fresh will detect bin files that start with `fresh-` in your `$PATH`.

For example running `fresh open` is equivalent to running `fresh-open`.

## Maintainers

fresh is maintained by [jasoncodes] and [twe4ked].
Expand Down
40 changes: 32 additions & 8 deletions bin/fresh
Original file line number Diff line number Diff line change
Expand Up @@ -696,13 +696,7 @@ See http://freshshell.com/readme for more documentation.
usage: fresh <command> [<args>]

Available commands:
install Build shell configuration and relevant symlinks (default)
update [<filter>] Update from source repos and rebuild
clean Removes dead symlinks and source repos
search <query> Search the fresh directory
edit Open freshrc for editing
show Show source references for freshrc lines
help Show this help
$(fresh_commands | sed -e 's/^/ /' -e 's/ #//')
EOF
}

Expand Down Expand Up @@ -798,6 +792,27 @@ _freshrc_file() {
echo "${FRESH_RCFILE/#$HOME/~}"
}

fresh_commands() {
shopt -s nullglob

cat <<EOF
install # Build shell configuration and relevant symlinks (default)
update [<filter>] # Update from source repos and rebuild
clean # Removes dead symlinks and source repos
search <query> # Search the fresh directory
edit # Open freshrc for editing
show # Show source references for freshrc lines
help # Show this help
EOF
{ for path in ${PATH//:/$'\n'}; do
for command in "${path}/fresh-"*; do
command="${command##*/fresh-}"
printf "%-19s# %s\n" "$command" "Run $command plugin"
done
done
} | sort | uniq
}

main() {
case "$1" in
help|--help)
Expand Down Expand Up @@ -828,11 +843,20 @@ main() {
_prevent_invalid_arguments "$@"
fresh_clean
;;
commands)
fresh_commands
;;
*)
if [[ "$1" == */* ]] || [[ -e "$FRESH_LOCAL/$1" ]]; then
fresh_add "$@"
else
_fatal_error "Unknown option: $1"
BIN_NAME="fresh-$1"
if which "$BIN_NAME" > /dev/null; then
shift
"$BIN_NAME" "$@"
else
_fatal_error "Unknown command: $1"
fi
fi
;;
esac
Expand Down
2 changes: 1 addition & 1 deletion contrib/completion/fresh-completion.bash
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
_fresh() {
local cur=${COMP_WORDS[COMP_CWORD]}
if [[ $COMP_CWORD == 1 ]]; then
local WORDS="install update clean search edit show help"
local WORDS="$(fresh commands | cut -d ' ' -f 1)"
elif [[ $COMP_CWORD == 2 ]] && [[ "${COMP_WORDS[1]}" =~ ^update$|^up$ ]]; then
local WORDS="$(
cd "$FRESH_PATH/source"
Expand Down
15 changes: 7 additions & 8 deletions contrib/completion/fresh-completion.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,13 @@

case $CURRENT in
2)
_values 'fresh command' \
'install[Build shell configuration and relevant symlinks (default)]' \
'update[Update from source repos and rebuild]' \
'clean[Remove dead symlinks and source repos]' \
'search[Search the fresh directory]' \
'edit[Open freshrc for editing]' \
'show[Show source references for freshrc lines]' \
'help[Show help]'
eval "$(
printf _values
printf " %q" "fresh command"
fresh commands | sed -e 's/^\([^ ]*\)[^#]*# \(.*\)$/\1[\2]/' | while read LINE; do
printf " %q" "$LINE"
done
)"
;;
3)
case "$words[2]" in
Expand Down
23 changes: 23 additions & 0 deletions test/fresh_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1671,4 +1671,27 @@ zsh config
EOF
}

it_runs_subcommands() {
bin="$SANDBOX_PATH/bin/fresh-foo"
echo "echo foobar" > $bin
chmod +x $bin

runFresh foo

assertFileMatches $SANDBOX_PATH/out.log <<EOF
foobar
EOF
assertFileMatches $SANDBOX_PATH/err.log <<EOF
EOF
}

it_errors_for_unknown_commands() {
runFresh fails foo
assertFileMatches $SANDBOX_PATH/out.log <<EOF
EOF
assertFileMatches $SANDBOX_PATH/err.log <<EOF
$ERROR_PREFIX Unknown command: foo
EOF
}

source test/test_helper.sh