Skip to content

Commit

Permalink
fix .helpers/foreach-script
Browse files Browse the repository at this point in the history
  • Loading branch information
moukoublen committed Oct 25, 2024
1 parent 8bcebca commit ea87568
Show file tree
Hide file tree
Showing 22 changed files with 133 additions and 127 deletions.
7 changes: 6 additions & 1 deletion .helpers/foreach-script
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@

VERBOSE=${VERBOSE:="0"}

__is_file_bash_or_sh() {
[[ ${1} == *.bash || ${1} == *.sh ]] ||
file "${1}" | grep -qE 'shell script|POSIX shell script|Bourne-Again shell script|bash script|a sh script'
}

mapfile -d '' -t files < <(
find ./ \
-type f \
Expand All @@ -21,7 +26,7 @@ mapfile -d '' -t files < <(
status=0

for file in "${files[@]}"; do
if file "${file}" | grep -qE 'shell script|POSIX shell script|Bourne-Again shell script|bash script|a sh script'; then
if __is_file_bash_or_sh "${file}"; then
[[ ${VERBOSE} == "1" ]] && echo "${*} ${file}"
"${@}" "${file}" || status=1
fi
Expand Down
4 changes: 3 additions & 1 deletion .helpers/shellcheck
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ fi
--exclude=SC2012 \
--exclude=SC2002 \
--exclude=SC2059 \
--exclude=SC2181
--exclude=SC2181 \
--exclude=SC1091

# SC2012 (info): Use find instead of ls to better handle non-alphanumeric filenames. https://www.shellcheck.net/wiki/SC2012
# SC2059 (info): Don't use variables in the printf format string. https://www.shellcheck.net/wiki/SC2059
# SC2002 (style): Useless cat. Consider 'cmd < file | ..' or 'cmd file | ..' instead. https://www.shellcheck.net/wiki/SC2002
# SC2181 (style): Check exit code directly with e.g. 'if ! mycmd;', not indirectly with $?. https://www.shellcheck.net/wiki/SC2181
# SC1091 (info): Not following: /usr/share/fzf/shell/key-bindings.bash: openBinaryFile: does not exist (No such file or directory). https://www.shellcheck.net/wiki/SC1091
4 changes: 0 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,3 @@ Run `install`.
$ ln -s /path/to/dotfiles/root.bash ~/.dotfiles.bash
$ echo '[[ -r ~/.dotfiles.bash ]] && [[ -f ~/.dotfiles.bash ]] && source ~/.dotfiles.bashh' >> ~/.bashrc
```

#### Notes

Create the file `~/.path` and put what ever path that you want to be included to PATH (paths can contain environment variables).
2 changes: 1 addition & 1 deletion bin/colors-sample
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ __msg2() {
}

__boxline() {
for v in "$@"; do
for v in "${@}"; do
__msg2 "${v}"
done
echo ""
Expand Down
4 changes: 2 additions & 2 deletions bin/provides
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

case "$(what-pm)" in
"dnf")
dnf provides "$@"
dnf provides "${@}"
;;
"apt")
dpkg -S "$@"
dpkg -S "${@}"
;;
*)
echo "this script does not supports this distro"
Expand Down
5 changes: 3 additions & 2 deletions config/gnome/lib/display-colors
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#!/usr/bin/env bash

# shellcheck disable=SC1090
source "$1"
# https://www.shellcheck.net/wiki/SC1090
# shellcheck source=/dev/null
source "${1}"

echo "FG : ${C_FG}"
echo "BG : ${C_BG}"
Expand Down
1 change: 0 additions & 1 deletion lib/00-common.bash
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,3 @@ bb() {
local cmd='source-highlight --no-doc --out-format=esc --tab=2'
${cmd} --infer-lang --input "${@}" 2>/dev/null || ${cmd} --src-lang=shell --input "${@}"
}

7 changes: 6 additions & 1 deletion lib/00-homebrew.bash
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ init-linuxbrew() {
if [ -d "${HOMEBREW_PREFIX}/etc/bash_completion.d" ]; then
for rc in "${HOMEBREW_PREFIX}/etc/bash_completion.d"/*; do
if [ -f "${rc}" ]; then
# https://www.shellcheck.net/wiki/SC1090
# shellcheck source=/dev/null
source "${rc}"
fi
done
Expand All @@ -20,13 +22,16 @@ case "$(uname)" in

if [[ -r "${HOMEBREW_PREFIX}/etc/profile.d/bash_completion.sh" ]]; then
export BASH_COMPLETION_COMPAT_DIR="${HOMEBREW_PREFIX}/etc/bash_completion.d"
# https://www.shellcheck.net/wiki/SC1090
# shellcheck source=/dev/null
source "${HOMEBREW_PREFIX}/etc/profile.d/bash_completion.sh"
fi
;;

"Linux")
[[ "${__DISABLE_LINUXBREW}" == 'true' ]] && return 0
[[ ${__DISABLE_LINUXBREW} == 'true' ]] && return 0
init-linuxbrew
;;

*) ;;
esac
19 changes: 4 additions & 15 deletions lib/00-pathmixer.bash
Original file line number Diff line number Diff line change
@@ -1,26 +1,15 @@
path-add() {
if [[ "${1}" == "" ]]; then
if [[ ${1} == "" ]]; then
return
fi

if [[ ":${PATH}:" != *":${1}:"* ]] ; then
if [[ "${2}" = "after" ]] ; then
if [[ ":${PATH}:" != *":${1}:"* ]]; then
if [[ ${2} == "after" ]]; then
PATH=${PATH}:${1}
else
PATH=${1}:${PATH}
fi
fi

export PATH;
}

load-path-file() {
if [ -f ~/.path ]; then
while read p; do
[[ ${p} = "" ]] && continue
p=$(eval echo \"${p}\")
path-add ${p}
done < ~/.path
unset p
fi
export PATH
}
9 changes: 4 additions & 5 deletions lib/10-linux.bash
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@ fi

################################################################################
######### Paths ################################################################
path-add ${HOME}/.local/bin
path-add ${HOME}/bin
path-add "${HOME}/.local/bin"
path-add "${HOME}/bin"
################################################################################
################################################################################


################################################################################
######### Aliases and Functions ################################################
alias O='xdg-open'
Expand All @@ -30,7 +29,7 @@ alias dnf-display-package-contents='dnf repoquery -l'
alias dnf-display-local-package-contents='dnf repoquery --installed -l'

sizes-files() {
du --human-readable --max-depth=1 --all | sort --human-numeric-sort --reverse
du --human-readable --max-depth=1 --all | sort --human-numeric-sort --reverse
}
export -f sizes-files
sizes-disks() {
Expand All @@ -52,5 +51,5 @@ export -f apt-clean-uninstalled

export EDITOR=/usr/bin/vim

[[ -e $HOME/.dir_colors ]] && eval "$(dircolors --bourne-shell ~/.dir_colors)"
[[ -e "${HOME}/.dir_colors" ]] && eval "$(dircolors --bourne-shell "${HOME}/.dir_colors")"
# dircolors --print-database > ~/.dir_colors
6 changes: 3 additions & 3 deletions lib/10-macos.bash
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ if [[ -d "${HOMEBREW_PREFIX}/opt/curl/bin" ]]; then
alias curl="\${HOMEBREW_PREFIX}/opt/curl/bin/curl"
fi

export LANG='en_US.UTF-8';
export LC_ALL='en_US.UTF-8';
export LANG='en_US.UTF-8'
export LC_ALL='en_US.UTF-8'

install-nano-nanorc() {
touch ~/.nanorc
for rcfile in "$(brew --prefix nano)"/share/nano/*.nanorc; do
echo "include ${rcfile}" >> ~/.nanorc
echo "include ${rcfile}" >>~/.nanorc
done
}

Expand Down
60 changes: 26 additions & 34 deletions lib/20-ps1.bash
Original file line number Diff line number Diff line change
Expand Up @@ -58,73 +58,67 @@
################################################################################

__ps1_color() {
if [[ "$#" = 0 ]]; then
if [[ $# == 0 ]]; then
printf "\[\e[0m\]"
else
printf "\[\e[${1};${2};${3}m\]"
fi
}

declare -A __PS1_COLORS=( \
["reset"]="$(__ps1_color)" \
["prefix"]="$(__ps1_color 1 49 35)" \
["main"]="$(__ps1_color 0 49 90)" \
["seperator"]="$(__ps1_color 0 49 37)" \
["user"]="$(__ps1_color 0 49 32)" \
["root"]="$(__ps1_color 0 49 31)" \
["path"]="$(__ps1_color 0 49 36)" \
["git"]="$(__ps1_color 0 49 93)" \
["gitwrap"]="$(__ps1_color 0 49 33)" \
["kube_context"]="$(__ps1_color 1 49 34)" \
["kube_nsp"]="$(__ps1_color 0 49 37)" \
declare -A __PS1_COLORS=(
["reset"]="$(__ps1_color)"
["prefix"]="$(__ps1_color 1 49 35)"
["main"]="$(__ps1_color 0 49 90)"
["seperator"]="$(__ps1_color 0 49 37)"
["user"]="$(__ps1_color 0 49 32)"
["root"]="$(__ps1_color 0 49 31)"
["path"]="$(__ps1_color 0 49 36)"
["git"]="$(__ps1_color 0 49 93)"
["gitwrap"]="$(__ps1_color 0 49 33)"
["kube_context"]="$(__ps1_color 1 49 34)"
["kube_nsp"]="$(__ps1_color 0 49 37)"
)



__ps1_seperator() {
#local DSEP=${__PS1_SEPERATOR:-$' \u2423 '} # https://codepoints.net/U+2423
#local DSEP=${__PS1_SEPERATOR:-$' \u203F '} # https://codepoints.net/U+203F
#local DSEP=${__PS1_SEPERATOR:-$' \u2219 '} # https://codepoints.net/U+2219
local DSEP=${__PS1_SEPERATOR:-$' \u2022 '} # https://codepoints.net/U+2022
local DSEP=${__PS1_SEPERATOR:-$' \u2022 '} # https://codepoints.net/U+2022
#local DSEP=${__PS1_SEPERATOR:-$' '}
printf "%s%s%s" "${__PS1_COLORS[seperator]}" "$DSEP" "${__PS1_COLORS[reset]}"
printf "%s%s%s" "${__PS1_COLORS[seperator]}" "${DSEP}" "${__PS1_COLORS[reset]}"
}


__ps1_user() {
local disp=${__PS1_DISPLAY_USER:-false}
if [[ "${disp}" == 'false' ]] && [[ ! "`id -u`" -eq 0 ]]; then
if [[ ${disp} == 'false' ]] && [[ ! "$(id -u)" -eq 0 ]]; then
return
fi

local USR="${__PS1_COLORS[user]}${USER}${__PS1_COLORS[reset]}"
if [[ "`id -u`" -eq 0 ]]; then
if [[ "$(id -u)" -eq 0 ]]; then
USR="${__PS1_COLORS[root]}root${__PS1_COLORS[reset]}"
fi

printf "%s" "${USR}"
}


__ps1_host() {
local disp=${__PS1_DISPLAY_HOSTNAME:-false}
if [[ "${disp}" == 'false' ]]; then
if [[ ${disp} == 'false' ]]; then
return
fi

local TO_PRINT=${__PS1_HOSTNAME:-$HOSTNAME}
local TO_PRINT=${__PS1_HOSTNAME:-${HOSTNAME}}

printf "%s%s%s" "${__PS1_COLORS[user]}" "${TO_PRINT}" "${__PS1_COLORS[reset]}"
}


__ps1_pwd() {
printf "%s\w%s" \
"${__PS1_COLORS[path]}" \
"${__PS1_COLORS[reset]}"
}


export GIT_PS1_SHOWDIRTYSTATE=true
export GIT_PS1_SHOWUNTRACKEDFILES=true
export GIT_PS1_SHOWUPSTREAM="verbose name"
Expand All @@ -139,7 +133,7 @@ __ps1_git() {

local gitp
gitp="$(__git_ps1 '%s')"
if [[ -n "${gitp}" ]]; then
if [[ -n ${gitp} ]]; then
printf "%s%s%s%s%s%s" \
"${__PS1_COLORS[gitwrap]}" \
$'\uE0A0 ' \
Expand All @@ -150,9 +144,8 @@ __ps1_git() {
fi
}


__ps1_kube() {
if [[ -z "${__PS1_DISPLAY_KUBE-}" ]] || [[ ! -x "$(command -v kubectl)" ]]; then
if [[ -z ${__PS1_DISPLAY_KUBE-} ]] || [[ ! -x "$(command -v kubectl)" ]]; then
return
fi

Expand All @@ -167,20 +160,20 @@ __ps1_join() {
sep="$(__ps1_seperator)"
local BUF=""

if [[ "$#" -eq 0 ]]; then
if [[ $# -eq 0 ]]; then
return
fi

for fn in "${@}"; do
[[ -z "$fn" ]] && continue
if [[ "${BUF}" == "" ]]; then
[[ -z ${fn} ]] && continue
if [[ ${BUF} == "" ]]; then
BUF="${fn}"
continue
fi
BUF="${BUF}${sep}${fn}"
done

printf "%s" "$BUF"
printf "%s" "${BUF}"
}

__ps1() {
Expand All @@ -201,9 +194,8 @@ __ps1() {

export PROMPT_COMMAND=__ps1


ps1-kube() {
if [[ -n "${__PS1_DISPLAY_KUBE-}" ]]; then
if [[ -n ${__PS1_DISPLAY_KUBE-} ]]; then
unset __PS1_DISPLAY_KUBE
else
export __PS1_DISPLAY_KUBE=true
Expand Down
2 changes: 1 addition & 1 deletion lib/21-starship.bash
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
if command -v starship &> /dev/null; then
if command -v starship &>/dev/null; then
export STARSHIP_CONFIG="${DOTFILES_PATH}/config/starship/starship.toml"
eval "$(starship init bash)"
fi
21 changes: 14 additions & 7 deletions lib/50-docker.bash
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,43 @@ alias docker-clean-volumes='docker volume rm $(docker volume ls -qf dangling=tru
docker-stop-all() {
for i in $(docker ps --format "{{.Names}}"); do
printf "Stoping %s ... " "${i}"
docker stop ${i} > /dev/null
if [ $? -eq 0 ]; then
docker stop "${i}" >/dev/null
if [[ $? -eq 0 ]]; then
printf "\e[1;32mDone!\e[m\n"
else
printf "\e[1;31mFailed!\e[m\n"
fi
done
}

docker-clean-all() {( set -x
docker-clean-all() { (
set -x
# --force Do not prompt for confirmation
docker system prune --force
docker image prune --force
docker network prune --force
docker volume prune --force
)}
); }

if command -v dr 1>/dev/null 2>&1; then
# https://www.shellcheck.net/wiki/SC1090
# shellcheck source=/dev/null
source <(dr --completion)
fi

################################################################################
################# macos docker #################################################
source-docker-bash-completion() {
local etc=/Applications/Docker.app/Contents/Resources/etc
if [[ -f ${etc}/docker.bash-completion ]]; then
source ${etc}/docker.bash-completion
if [[ -f "${etc}/docker.bash-completion" ]]; then
# https://www.shellcheck.net/wiki/SC1090
# shellcheck source=/dev/null
source "${etc}/docker.bash-completion"
fi
if [[ -f ${etc}/docker-compose.bash-completion ]]; then
source ${etc}/docker-compose.bash-completion
# https://www.shellcheck.net/wiki/SC1090
# shellcheck source=/dev/null
source "${etc}/docker-compose.bash-completion"
fi
}
export -f source-docker-bash-completion
Expand Down
Loading

0 comments on commit ea87568

Please sign in to comment.