Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Allows users to declare custom aliases #247

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

Open
wants to merge 7 commits into
base: main
Choose a base branch
Loading
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Allows users to declare custom aliases
  • Loading branch information
nkakouros committed Nov 20, 2018
commit c88c65e8c285407e3eaf3ef58f58c87d7f247054
6 changes: 5 additions & 1 deletion 6 go-core.bash
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,11 @@ declare _GO_INJECT_MODULE_PATH="$_GO_INJECT_MODULE_PATH"
esac

if _@go.source_builtin 'aliases' --exists "$cmd"; then
eval "$cmd" "$@"
if [[ " ${GO_ALIAS_EXPAND_CMDS[*]} " == *" $cmd "* ]]; then
eval "$cmd" "$@"
else
"$cmd" "$@"
fi
return
fi

Expand Down
4 changes: 4 additions & 0 deletions 4 libexec/aliases
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ if [[ "${GO_ALIAS_CMDS_EXTRA[*]}" != '' ]]; then
_GO_ALIAS_CMDS+=( "${GO_ALIAS_CMDS_EXTRA[@]}" )
fi

if [[ "${GO_ALIAS_EXPAND_CMDS[*]}" != '' ]]; then
_GO_ALIAS_CMDS+=( "${GO_ALIAS_EXPAND_CMDS[@]}" )
fi

readonly _GO_ALIAS_CMDS

_@go.aliases() {
Expand Down
23 changes: 17 additions & 6 deletions 23 tests/aliases.bats
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,33 @@ load environment
create_aliases_test_command_script() {
@go.create_test_go_script \
'declare -a GO_ALIAS_CMDS_EXTRA=("nvim")' \
"@go $@"
'declare -a GO_ALIAS_EXPAND_CMDS=("test_echo")' \
'shopt -s expand_aliases' \
'alias test_echo="echo -n test_string_19098e09818fad"' \
"@go \$@"
}

@test "$SUITE: with no arguments, list all aliases" {
@test "$SUITE: with no arguments, list all predefined aliases" {
run ./go aliases
assert_success
assert_line_equals 0 'awk' # first alias
assert_line_equals -1 'sed' # last alias
}

@test "$SUITE: list custom aliases if defined" {
create_aliases_test_command_script 'aliases'
run "$TEST_GO_SCRIPT" aliases
create_aliases_test_command_script
run "$TEST_GO_SCRIPT" 'aliases'
assert_success
assert_line_equals 0 'awk' # first alias
assert_line_equals -1 'nvim' # last alias
assert_line_equals -2 'nvim' # second to last alias
assert_line_equals -1 'test_echo' # last alias
}

@test "$SUITE: run expanded aliases if defined" {
create_aliases_test_command_script 'aliases'
run "$TEST_GO_SCRIPT" 'test_echo'
assert_success
assert_line_equals 0 'test_string_19098e09818fad'
}

@test "$SUITE: tab completions" {
Expand Down Expand Up @@ -112,7 +123,7 @@ create_aliases_test_command_script() {
@test "$SUITE: leave help generic for cd, pushd when using env function" {
# Setting _GO_CMD will trick the script into thinking the shell function is
# running it.

_GO_CMD='test-go' run ./go aliases --help cd
[ "$status" -eq '0' ]

Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.