6 Commits

Author SHA1 Message Date
Noah Gorny
40d154cb16 Merge pull request #1689 from NoahGorny/rename-bash-it-update-internal
Rename _bash-it_update to _bash-it-update
2020-10-25 21:08:46 +02:00
Noah Gorny
825fc88a8f Rename _bash-it_update to _bash-it-update 2020-10-25 15:24:19 +02:00
Noah Gorny
c7d67aedb9 Merge pull request #1685 from NoahGorny/binary-exists
Add _binary_exists and use in github-cli completion
2020-10-21 11:23:31 +03:00
Noah Gorny
3838f12498 Add tests for _binary_exists 2020-10-21 11:02:55 +03:00
BarbUk
5e65235d0e Theme barbuk - add venv glyph and fix venv display in ssh mode (#1681)
* Add python venv glyph

* Fix venv display (tested for local and ssh prompt)

* Add documentation for python venv
2020-10-21 00:27:48 +03:00
Noah Gorny
8a36f21ca1 Add _binary_exists and use in github-cli completion
gh was also used as an git alias, and caused _command_exists to not fail as expected
2020-10-21 00:14:11 +03:00
5 changed files with 49 additions and 10 deletions

View File

@@ -2,7 +2,7 @@
cite "about-completion"
about-completion "GitHub CLI completion"
if _command_exists gh; then
if _binary_exists gh; then
if _command_exists brew; then
_log_warning "You don't need github-cli completion enabled if you have system completion enabled"
fi

View File

@@ -26,6 +26,17 @@ function _command_exists ()
type "$1" &> /dev/null || (_log_warning "$msg" && return 1) ;
}
function _binary_exists ()
{
_about 'checks for existence of a binary'
_param '1: binary to check'
_param '2: (optional) log message to include when binary not found'
_example '$ _binary_exists ls && echo exists'
_group 'lib'
local msg="${2:-Binary '$1' does not exist!}"
type -P "$1" &> /dev/null || (_log_warning "$msg" && return 1) ;
}
function _make_reload_alias() {
echo "source \${BASH_IT}/scripts/reloader.bash ${1} ${2}"
}
@@ -80,7 +91,7 @@ bash-it ()
_bash-it-search $component "$@"
return;;
update)
func=_bash-it_update-$component;;
func=_bash-it-update-$component;;
migrate)
func=_bash-it-migrate;;
version)
@@ -158,18 +169,18 @@ _bash-it-plugins ()
_bash-it-describe "plugins" "a" "plugin" "Plugin"
}
_bash-it_update-dev() {
_bash-it-update-dev() {
_about 'updates Bash-it to the latest master'
_group 'lib'
_bash-it_update- dev "$@"
_bash-it-update- dev "$@"
}
_bash-it_update-stable() {
_bash-it-update-stable() {
_about 'updates Bash-it to the latest tag'
_group 'lib'
_bash-it_update- stable "$@"
_bash-it-update- stable "$@"
}
_bash-it_pull_and_update_inner() {
@@ -187,7 +198,7 @@ _bash-it_pull_and_update_inner() {
fi
}
_bash-it_update-() {
_bash-it-update-() {
_about 'updates Bash-it'
_param '1: What kind of update to do (stable|dev)'
_group 'lib'

View File

@@ -39,6 +39,26 @@ function local_setup {
assert_failure
}
@test "helpers: _binary_exists function exists" {
run type -a _binary_exists &> /dev/null
assert_success
}
@test "helpers: _binary_exists function positive test ls" {
run _binary_exists ls
assert_success
}
@test "helpers: _binary_exists function negative test function" {
run _binary_exists _binary_exists
assert_failure
}
@test "helpers: _binary_exists function negative test" {
run _binary_exists __addfkds_dfdsjdf
assert_failure
}
@test "helpers: bash-it help aliases ag" {
run bash-it help aliases "ag"
assert_line -n 0 "ag='ag --smart-case --pager=\"less -MIRFX'"

View File

@@ -29,6 +29,7 @@ BARBUK_GIT_BRANCH_ICON=''
BARBUK_HG_CHAR='☿ '
BARBUK_SVN_CHAR='⑆ '
BARBUK_EXIT_CODE_ICON=' '
BARBUK_PYTHON_VENV_CHAR=' '
```
### Customize glyphs
@@ -97,3 +98,9 @@ chmod 400 /etc/sudoers.d/keepenv
```bash
user@hostname in  ~/bash-it on  master ✓
```
### Python venv
```bash
  flask ~/test on  master ✓
```

View File

@@ -10,6 +10,7 @@ SCM_GIT_CHAR_ICON_BRANCH=${BARBUK_GIT_BRANCH_ICON:=''}
SCM_HG_CHAR=${BARBUK_HG_CHAR:='☿ '}
SCM_SVN_CHAR=${BARBUK_SVN_CHAR:='⑆ '}
EXIT_CODE_ICON=${BARBUK_EXIT_CODE_ICON:=' '}
PYTHON_VENV_CHAR=${BARBUK_PYTHON_VENV_CHAR:=' '}
# Ssh user and hostname display
SSH_INFO=${BARBUK_SSH_INFO:=true}
@@ -90,12 +91,12 @@ function _prompt {
# Detect python venv
if [[ -n "${CONDA_DEFAULT_ENV}" ]]; then
python_venv="${CONDA_DEFAULT_ENV}"
python_venv="$PYTHON_VENV_CHAR${CONDA_DEFAULT_ENV} "
elif [[ -n "${VIRTUAL_ENV}" ]]; then
python_venv=$(basename "${VIRTUAL_ENV}")
python_venv="$PYTHON_VENV_CHAR$(basename "${VIRTUAL_ENV}") "
fi
PS1="\\n${ssh_info} ${python_venv} ${purple}$(scm_char)${dir_color}\\w${normal}$(scm_prompt_info)${exit_code}"
PS1="\\n${ssh_info} ${purple}$(scm_char)${python_venv}${dir_color}\\w${normal}$(scm_prompt_info)${exit_code}"
[[ ${#PS1} -gt $((COLUMNS*3)) ]] && wrap_char="\\n"
PS1="${PS1}${wrap_char}${normal} "