commit dce3ca3918a03214326c1d1480e7f60bd865b876 parent 36951e312d6226bb21cf87a7a38f7f8c41c22420 Author: Pablo Cárdenas <pablo.cardenas@imca.edu.pe> Date: Mon, 3 Jun 2024 22:22:15 -0500 bash: move alias and functions outside .bashrc Diffstat:
| M | .bashrc | | | 75 | +++++++++++++++++---------------------------------------------------------- |
| A | .config/shell/alias.sh | | | 3 | +++ |
| A | .config/shell/functions.sh | | | 77 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
3 files changed, 97 insertions(+), 58 deletions(-)
diff --git a/.bashrc b/.bashrc @@ -21,66 +21,25 @@ GPG_TTY=$(tty) PS1='\$ ' -alias ls='ls -AF' -alias vim='vim -u ~/.vim/vimrc' -alias dotfiles='git --git-dir "$HOME"/.dotfiles --work-tree "$HOME"' - -cd() { echo "Use pushd!"; } - -man() { - if [[ $1 == -* || $1 == [1-9]* || $1 == n ]] ; then - command man "$@" - else - echo "Specify section" - return 1 - fi -} - -git() { - if [ "$1" = "--git-dir" ]; then - local git_args+=("$1" "$2") - shift 2 - fi - if [ "$1" = "--work-tree" ]; then - local git_args+=("$1" "$2") - shift 2 - fi - - if [ "$1" = "checkout" ]; then - echo "Use" - echo " - git checkout-index -fu" - echo " - git read-tree --cached -u" - elif [ "$1" = "reset" ]; then - echo "Use" - echo " - git read-tree -mu" - echo " - git read-tree -m" - echo " - git update-index --add --remove --cacheinfo 100644 sha1 filename" - elif [ "$1" = "status" ] && [ $# = 1 ]; then - echo "Use" - echo " - git diff-index --cached HEAD" - echo " - git diff-files" - echo " - git ls-files --exclude-standard -o" - echo " - git status -bs" - elif [ "$1" = "log" ]; then - echo "Use" - echo " - git rev-list HEAD" - else - command git "${git_args[@]}" "$@" - fi -} - # shellcheck disable=SC2016 PROMPT_COMMAND+=( - '{ [ -z "$TMUX" ] && [[ $TERM != tmux-* ]] && [ "$ASCIINEMA_REC" != 1 ] && [ -n "$DISPLAY" -o -n "$TERMUX_VERSION" -o -n "$MSYSTEM" ]; } && { [ -z "$FIRST_COMMAND" ] && FIRST_COMMAND=1 || exit; }' + '{ + [[ -z "$TMUX" ]] && + [[ $TERM != tmux-* ]] && + [[ "$ASCIINEMA_REC" != 1 ]] && { + [[ -n "$DISPLAY" ]] || + [[ -n "$TERMUX_VERSION" ]] || + [[ -n "$MSYSTEM" ]] + } + } && { + [[ -z "$FIRST_COMMAND" ]] && + FIRST_COMMAND=1 || exit; + }' ) -print_goodbye() { - # shellcheck disable=SC2016 - if [ -z "${TMUX}" ] && { [ -n "$(dotfiles ls-files --others --exclude-standard --directory --no-empty-directory || true)" ] || ! dotfiles submodule foreach '[ -z "$(git ls-files --modified --others --exclude-standard --directory --no-empty-directory)" ]'>/dev/null 2>/dev/null; }; then - echo "In dotfiles:" - dotfiles status -s - dotfiles submodule foreach 'git status -s' - read -rn 1 - fi -} +# shellcheck source=.config/shell/alias.sh +source "${XDG_CONFIG_HOME:-${HOME}/.config}"/shell/alias.sh +# shellcheck source=.config/shell/functions.sh +source "${XDG_CONFIG_HOME:-${HOME}/.config}"/shell/functions.sh + trap print_goodbye EXIT diff --git a/.config/shell/alias.sh b/.config/shell/alias.sh @@ -0,0 +1,3 @@ +alias ls='ls -AF' +alias vim='vim -u ~/.vim/vimrc' +alias dotfiles='git --git-dir "${HOME}"/.dotfiles --work-tree "${HOME}"' diff --git a/.config/shell/functions.sh b/.config/shell/functions.sh @@ -0,0 +1,77 @@ +# shellcheck shell=sh + +cd() { echo "Use pushd!"; } + +man() { + case $1 in + -* | [1-9]* | n) + command man "$@" + ;; + *) + echo "Specify section" + return 1 + esac +} + +git() { + if [ "$1" = "--git-dir" ]; then + _git_dir="$2" + shift 2 + fi + if [ "$1" = "--work-tree" ]; then + _work_tree="$2" + shift 2 + fi + + if [ "$1" = "checkout" ]; then + echo "Use" + echo " - git checkout-index -fu" + echo " - git read-tree --cached -u" + elif [ "$1" = "reset" ]; then + echo "Use" + echo " - git read-tree -mu" + echo " - git read-tree -m" + echo " - git update-index --add --remove \ +--cacheinfo 100644 sha1 filename" + elif [ "$1" = "status" ] && [ $# = 1 ]; then + echo "Use" + echo " - git diff-index --cached HEAD" + echo " - git diff-files" + echo " - git ls-files --exclude-standard -o" + echo " - git status -bs" + elif [ "$1" = "log" ]; then + echo "Use" + echo " - git rev-list HEAD" + else + if [ -n "${_git_dir}" ]; then + set -- --git-dir "${_git_dir}" "$@" + fi + if [ -n "${_work_tree}" ]; then + set -- --work-tree "${_work_tree}" "$@" + fi + command git "$@" + unset _git_dir _work_tree + fi +} + +print_goodbye() { + set -- \ + --modified \ + --others \ + --exclude-standard \ + --directory \ + --no-empty-directory + # shellcheck disable=SC2016 + if [ -z "${TMUX}" ] && { + [ -n "$(dotfiles ls-files "$@" || true)" ] || + ! dotfiles submodule foreach '[ -z "$(git ls-files "$@")" ]' \ + >/dev/null 2>/dev/null; + }; then + echo "In dotfiles:" + dotfiles status -s + dotfiles submodule foreach 'git status -s' + read -r var + echo "${var}" + unset var + fi +}