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

shfmt and shellcheck for a few more files #2274

Open
wants to merge 5 commits 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: 4 additions & 6 deletions clean_files.txt
Original file line number Diff line number Diff line change
Expand Up @@ -130,18 +130,16 @@ plugins/available/pyenv.plugin.bash
plugins/available/python.plugin.bash
plugins/available/rbenv.plugin.bash
plugins/available/ruby.plugin.bash
plugins/available/sudo.plugin.bash
plugins/available/textmate.plugin.bash
plugins/available/thefuck.plugin.bash
plugins/available/todo.plugin.bash
plugins/available/url.plugin.bash
plugins/available/virtualenv.plugin.bash
plugins/available/xterm.plugin.bash
plugins/available/z_autoenv.plugin.bash
plugins/available/zoxide.plugin.bash

# tests
#
test/completion/aliases.completion.bats
test/run
test/test_helper.bash

# themes
#
themes/90210
Expand Down
23 changes: 12 additions & 11 deletions plugins/available/sudo.plugin.bash
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
# shellcheck shell=bash
cite about-plugin
about-plugin 'Toggle sudo at the beginning of the current or the previous command by hitting the ESC key twice'

function sudo-command-line() {
about "toggle sudo at the beginning of the current or the previous command by hitting the ESC key twice"
group "sudo"
about "toggle sudo at the beginning of the current or the previous command by hitting the ESC key twice"
group "sudo"

[[ ${#READLINE_LINE} -eq 0 ]] && READLINE_LINE=$(fc -l -n -1 | xargs)
if [[ $READLINE_LINE == sudo\ * ]]; then
READLINE_LINE="${READLINE_LINE#sudo }"
else
READLINE_LINE="sudo $READLINE_LINE"
fi
READLINE_POINT=${#READLINE_LINE}
[[ ${#READLINE_LINE} -eq 0 ]] && READLINE_LINE=$(fc -l -n -1 | xargs)
if [[ $READLINE_LINE == sudo\ * ]]; then
READLINE_LINE="${READLINE_LINE#sudo }"
else
READLINE_LINE="sudo $READLINE_LINE"
fi
READLINE_POINT=${#READLINE_LINE}
}

# Define shortcut keys: [Esc] [Esc]

# Readline library requires bash version 4 or later
if [ "${BASH_VERSINFO}" -ge 4 ]; then
bind -x '"\e\e": sudo-command-line'
if [ "${BASH_VERSINFO[0]}" -ge 4 ]; then
bind -x '"\e\e": sudo-command-line'
fi
5 changes: 3 additions & 2 deletions plugins/available/thefuck.plugin.bash
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# shellcheck shell=bash
cite about-plugin
about-plugin 'Initialization for fuck'

# https://github.com/nvbn/thefuck

if _command_exists thefuck; then
# shellcheck disable=SC2046
eval $(thefuck --alias)
# shellcheck disable=SC2046
eval $(thefuck --alias)
fi
32 changes: 15 additions & 17 deletions plugins/available/virtualenv.plugin.bash
Original file line number Diff line number Diff line change
Expand Up @@ -11,35 +11,33 @@ elif _command_exists virtualenvwrapper.sh; then
source virtualenvwrapper.sh
fi


function mkvenv {
about 'create a new virtualenv for this directory'
group 'virtualenv'
about 'create a new virtualenv for this directory'
group 'virtualenv'

local cwd="${PWD##*/}"
mkvirtualenv --distribute "$cwd"
local cwd="${PWD##*/}"
mkvirtualenv --distribute "$cwd"
}


function mkvbranch {
about 'create a new virtualenv for the current branch'
group 'virtualenv'
about 'create a new virtualenv for the current branch'
group 'virtualenv'

local cwd="${PWD##*/}"
mkvirtualenv --distribute "${cwd}@${SCM_BRANCH}"
local cwd="${PWD##*/}"
mkvirtualenv --distribute "${cwd}@${SCM_BRANCH}"
}

function wovbranch {
about 'sets workon branch'
group 'virtualenv'
about 'sets workon branch'
group 'virtualenv'

local cwd="${PWD##*/}"
workon "${cwd}@${SCM_BRANCH}"
local cwd="${PWD##*/}"
workon "${cwd}@${SCM_BRANCH}"
}

function wovenv {
about 'works on the virtualenv for this directory'
group 'virtualenv'
about 'works on the virtualenv for this directory'
group 'virtualenv'

workon "${PWD##*/}"
workon "${PWD##*/}"
}
68 changes: 33 additions & 35 deletions plugins/available/z_autoenv.plugin.bash
Original file line number Diff line number Diff line change
@@ -1,45 +1,43 @@
# shellcheck shell=bash
# shellcheck disable=SC2207
cite about-plugin
about-plugin 'source into environment when cding to directories'

if [[ -n "${ZSH_VERSION}" ]]
then __array_offset=0
else __array_offset=1
if [[ -n "${ZSH_VERSION}" ]]; then
__array_offset=0
else
__array_offset=1
fi

autoenv_init()
{
typeset target home _file
typeset -a _files
target=$1
home="${HOME%/*}"
function autoenv_init {
typeset home _file
typeset -a _files
home="${HOME%/*}"

_files=( $(
while [[ "$PWD" != "/" && "$PWD" != "$home" ]]
do
_file="$PWD/.env"
if [[ -e "${_file}" ]]
then echo "${_file}"
fi
builtin cd ..
done
) )
_files=($(
while [[ "$PWD" != "/" && "$PWD" != "$home" ]]; do
_file="$PWD/.env"
if [[ -e "${_file}" ]]; then
echo "${_file}"
fi
builtin cd .. || return
done
))

_file=${#_files[@]}
while (( _file > 0 ))
do
source "${_files[_file-__array_offset]}"
: $(( _file -= 1 ))
done
_file=${#_files[@]}
while ((_file > 0)); do
# shellcheck disable=SC1090
source "${_files[_file - __array_offset]}"
: $((_file -= 1))
done
}

cd()
{
if builtin cd "$@"
then
autoenv_init
return 0
else
echo "else?"
return $?
fi
cd() {
if builtin cd "$@"; then
autoenv_init
return 0
else
echo "else?"
return $?
fi
}
Loading