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

fix: Quoting #432

Merged
merged 5 commits into from
May 14, 2023
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
70 changes: 36 additions & 34 deletions completions/django.completion.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#! bash oh-my-bash.module
# Upstream: https://github.com/django/django/blob/90c59b4e12e6ff41407694a460f5f30c4688dbfd/extras/django_bash_completion
#
# #########################################################################
# This bash script adds tab-completion feature to django-admin.py and
# manage.py.
# This bash script adds tab-completion feature to django-admin and manage.py.
#
# Testing it out without installing
# =================================
Expand Down Expand Up @@ -32,42 +33,43 @@
#
# To uninstall, just remove the line from your .bash_profile and .bashrc.

_django_completion()
{
COMPREPLY=( $( COMP_WORDS="${COMP_WORDS[*]}" \
COMP_CWORD=$COMP_CWORD \
DJANGO_AUTO_COMPLETE=1 $1 ) )
function _omb_completion_django {
COMPREPLY=($(COMP_WORDS="${COMP_WORDS[*]}" \
COMP_CWORD=$COMP_CWORD \
DJANGO_AUTO_COMPLETE=1 "$1"))
}
complete -F _django_completion -o default django-admin.py manage.py django-admin
# When the django-admin.py deprecation ends, remove django-admin.py.
complete -F _omb_completion_django -o default manage.py django-admin

_python_django_completion()
{
if [[ ${COMP_CWORD} -ge 2 ]]; then
PYTHON_EXE=$( basename -- ${COMP_WORDS[0]} )
echo $PYTHON_EXE | command grep -E "python([2-9]\.[0-9])?" >/dev/null 2>&1
if [[ $? == 0 ]]; then
PYTHON_SCRIPT=$( basename -- ${COMP_WORDS[1]} )
echo $PYTHON_SCRIPT | command grep -E "manage\.py|django-admin(\.py)?" >/dev/null 2>&1
if [[ $? == 0 ]]; then
COMPREPLY=( $( COMP_WORDS="${COMP_WORDS[*]:1}" \
COMP_CWORD=$(( COMP_CWORD-1 )) \
DJANGO_AUTO_COMPLETE=1 ${COMP_WORDS[*]} ) )
fi
fi
function _omb_completion_django_python {
if ((COMP_CWORD >= 2)); then
if command grep -qE "python([3-9]\.[0-9])?" <<< "${COMP_WORDS[0]##*/}"; then
if command grep -qE "manage\.py|django-admin" <<< "${COMP_WORDS[1]##*/}"; then
COMPREPLY=($(COMP_WORDS="${COMP_WORDS[*]:1}" \
COMP_CWORD=$((COMP_CWORD - 1)) \
DJANGO_AUTO_COMPLETE=1 "${COMP_WORDS[@]}"))
fi
fi
fi
}

# Support for multiple interpreters.
unset pythons
if _omb_util_command_exists whereis; then
python_interpreters=$(whereis python | cut -d " " -f 2-)
for python in $python_interpreters; do
pythons="${pythons} $(basename -- $python)"
function _omb_completion_django_init {
# Support for multiple interpreters.
local -a pythons=(python)
if _omb_util_command_exists whereis; then
local python_interpreters
_omb_util_split python_interpreters "$(whereis python | cut -d " " -f 2-)"
local python
for python in "${python_interpreters[@]}"; do
[[ -x $python ]] || continue
[[ $python == *-config ]] || continue
python=${python##*/}
[[ $python ]] && pythons+=("$python")
done
pythons=$(echo $pythons | tr " " "\n" | sort -u | tr "\n" " ")
else
pythons=python
fi

complete -F _python_django_completion -o default $pythons
_omb_util_split pythons "$(printf '%s\n' "${pythons[@]}" | sort -u)" $'\n'
fi

complete -F _omb_completion_django_python -o default "${pythons[@]}"
unset -f "$FUNCNAME"
}
_omb_completion_django_init
2 changes: 1 addition & 1 deletion completions/gh.completion.sh
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ EOF
((c++))
done
if [ -z "$name" ]; then
repo=$(basename "$(pwd)")
repo=$(basename "$PWD")
fi
case "$prev" in
-d|-h)
Expand Down
2 changes: 1 addition & 1 deletion completions/hub.completion.sh
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ EOF
((c++))
done
if [ -z "$name" ]; then
repo=$(basename "$(pwd)")
repo=$(basename "$PWD")
fi
case "$prev" in
-d|-h)
Expand Down
4 changes: 2 additions & 2 deletions completions/vagrant.completion.sh
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ function _vagrant {
vagrant_state_file=$(__vagrantinvestigate) || return 1
if [[ -f $vagrant_state_file ]]
then
running_vm_list=$(grep 'active' $vagrant_state_file | sed -e 's/"active"://' | tr ',' '\n' | cut -d '"' -f 2 | tr '\n' ' ')
running_vm_list=$(grep 'active' "$vagrant_state_file" | sed -e 's/"active"://' | tr ',' '\n' | cut -d '"' -f 2 | tr '\n' ' ')
else
running_vm_list=$(find $vagrant_state_file -type f -name "id" | awk -F"/" '{print $(NF-2)}')
running_vm_list=$(find "$vagrant_state_file" -type f -name "id" | awk -F"/" '{print $(NF-2)}')
fi
COMPREPLY=($(compgen -W "${running_vm_list}" -- ${cur}))
return 0
Expand Down
2 changes: 1 addition & 1 deletion completions/vault.completion.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function _vault() {
if [[ $prev =~ ^(policies|policy-write|policy-delete) ]]; then
local policies=$(vault policies 2> /dev/null)
COMPREPLY=($(compgen -W "$policies" -- $cur))
elif [ "$(echo $line | wc -w)" -le 2 ]; then
elif [ "$(echo "$line" | wc -w)" -le 2 ]; then
if [[ "$line" =~ ^vault\ (read|write|delete|list)\ $ ]]; then
COMPREPLY=($(compgen -W "$(_vault_mounts)" -- ''))
else
Expand Down
6 changes: 3 additions & 3 deletions lib/omb-prompt-base.sh
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ function git_prompt_vars {
command git status --porcelain ${git_status_flags} 2> /dev/null) | git_status_summary)
local status=$(awk 'NR==1' <<< "$status_lines")
local counts=$(awk 'NR==2' <<< "$status_lines")
IFS=$'\t' read untracked_count unstaged_count staged_count <<< "$counts"
IFS=$'\t' read -r untracked_count unstaged_count staged_count <<< "$counts"
if [[ "${untracked_count}" -gt 0 || "${unstaged_count}" -gt 0 || "${staged_count}" -gt 0 ]]; then
SCM_DIRTY=1
if [[ "${SCM_GIT_SHOW_DETAILS}" = "true" ]]; then
Expand Down Expand Up @@ -341,15 +341,15 @@ function svn_prompt_vars {
# - .hg is located in ~/Projects/Foo/.hg
# - get_hg_root starts at ~/Projects/Foo/Bar and sees that there is no .hg directory, so then it goes into ~/Projects/Foo
function get_hg_root {
local CURRENT_DIR=$(pwd)
local CURRENT_DIR=$PWD

while [ "$CURRENT_DIR" != "/" ]; do
if [ -d "$CURRENT_DIR/.hg" ]; then
echo "$CURRENT_DIR/.hg"
return
fi

CURRENT_DIR=$(dirname $CURRENT_DIR)
CURRENT_DIR=$(dirname "$CURRENT_DIR")
done
}

Expand Down
1 change: 1 addition & 0 deletions lib/readlink.sh
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ function _omb_util_readlink__resolve {
readlink=$(type -P readlink)
case $readlink in
(/bin/readlink | /usr/bin/readlink)
# shellcheck disable=SC2100
_omb_util_readlink_type=readlink-f
function _omb_util_readlink__resolve { readlink -f -- "$1"; } ;;
esac ;;
Expand Down
12 changes: 11 additions & 1 deletion lib/utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ function _omb_log_note { printf "${_omb_term_underline}${_omb_term_bold}${_
#
function seek_confirmation {
printf "\\n${_omb_term_bold}%s${_omb_term_reset}" "$@"
read -p " (y/n) " -n 1
read -rp " (y/n) " -n 1
printf "\\n"
}

Expand Down Expand Up @@ -309,6 +309,7 @@ function _omb_util_unload {
}

_omb_util_original_PS1=$PS1
# shellcheck disable=SC2016
_omb_util_unload_hook+=('PS1=$_omb_util_original_PS1')

_omb_util_prompt_command=()
Expand Down Expand Up @@ -364,6 +365,15 @@ function _omb_util_add_prompt_command {
fi
}

## @fn _omb_util_split array str [sep]
function _omb_util_split {
local __set=$- IFS=${3:-$' \t\n'}
set -f
eval -- "$1=(\$2)"
[[ $__set == *f* ]] || set +f
return 0
}

function _omb_util_glob_expand {
local __set=$- __shopt __gignore=$GLOBIGNORE
_omb_util_get_shopt failglob nullglob extglob
Expand Down
2 changes: 1 addition & 1 deletion themes/agnoster/agnoster.theme.sh
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@
# export THEME=$HOME/.bash/themes/agnoster-bash/agnoster.bash
# if [[ -f $THEME ]]; then
# export DEFAULT_USER=$(whoami)
# source $THEME
# source "$THEME"
# fi

#
Expand Down
4 changes: 2 additions & 2 deletions themes/duru/duru.theme.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ SCM_THEME_PROMPT_DIRTY=" ${_omb_prompt_brown}with changes"
SCM_THEME_PROMPT_CLEAN=""

function venv {
if [ ! -z "$VIRTUAL_ENV" ]
if [ -n "$VIRTUAL_ENV" ]
then
local env=$VIRTUAL_ENV
echo "${gray} in ${_omb_prompt_red}${env##*/} "
fi
}

function last_two_dirs {
pwd|rev|awk -F / '{print $1,$2}'|rev|sed s_\ _/_|sed "s|$(sed 's,\/,,'<<<$HOME)|~|g"
pwd|rev|awk -F / '{print $1,$2}'|rev|sed s_\ _/_|sed "s|$(sed 's,\/,,'<<<"$HOME")|~|g"
}

function _omb_theme_PROMPT_COMMAND {
Expand Down
2 changes: 1 addition & 1 deletion themes/hawaii50/hawaii50.theme.sh
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ function limited_pwd() {
# Replace $HOME with ~ if possible
local RELATIVE_PWD=${PWD/#$HOME/\~}

local offset=$((${#RELATIVE_PWD}-$MAX_PWD_LENGTH))
local offset=$((${#RELATIVE_PWD}-MAX_PWD_LENGTH))

if ((offset > 0)); then
local truncated_symbol="..."
Expand Down