dotfiles/config/bashrc/functions

88 lines
2.8 KiB
Bash

#!/bin/bash
# shellcheck disable=SC2199,SC2068,SC1091,SC2086,SC2145
# SPDX-License-Identifier: MPL-2.0
DOTFILES_HOME=${DOTFILES_HOME:-"$HOME/.dotfiles"}
source "$DOTFILES_HOME/tools/bootstrap-utils/00-script-library.sh"
disable-funcs () {
echo "info: Unimplemented yet. Tell Andrei to add it to his todo."
}
edit-funcs-bashrc() {
$(command -v nano>>/dev/null && echo nano || echo vi) ~/.dotfiles/bashrc/functions
}
list-debs-size() {
dpkg-query -Wf '${Installed-Size}\t${Package}\n' | sort -rn | less
}
edit-script-file() {
# if you use other editor, please set $EDITOR.
${EDITOR:-"nano"} "$(command -v $1)"
}
# Refreshing shell with latest updates
refresh-funcs() {
showStage "reloading current session with fresh functions"
source "$DOTFILES_HOME/config/bashrc/functions"
}
refresh-aliases() {
showStage "reloading current session with fresh aliases"
source "$DOTFILES_HOME/config/bashrc/aliases"
}
# https://commentedcode.org/blog/2020/09/21/changing-default-branch-of-git-init/
# TODO: Deprecate this function once git-config:init.defaultBranch is used.
git() {
# check command for some automation KEK, especially i want to do DCO by default
if [[ "$1" == "init" && "$@" != *"--help"* ]]; then
if command git "$@"; then
echo "Setting HEAD to branch main"
command git symbolic-ref HEAD refs/heads/main
fi
else
command git "$@"
fi
}
list-nodejs-scripts() {
[[ -f "package.json" ]] && jq .scripts < package.json || echo "No package.json found in current directory."
}
# TODO: Support code-server from Coder and Gitpod's OpenVSCode Server.
# TODO: Might also add support for Theia IDE too soon.
code() {
# quick trick in case only code-insiders is installed and not code
if [[ $(type -p code) == "" ]]; then
if command -v code-insiders >>/dev/null; then
warn "code is not installed, but code-insiders is found in PATH, setting USE_CODE_INSIDERS"
warn "for this run behind the scenes for you"
USE_CODE_INSIDERS=true
fi
fi
if [[ -f "/snap/bin/code" && "$USE_CODE_INSIDERS" == "" ]]; then
echo "info: execing /snap/bin/code with params: $*"
/snap/bin/code "$@"
elif [[ -f "/snap/bin/code-insiders" ]]; then
echo "info: execing /snap/bin/code-insiders with params: $*"
/snap/bin/code-insiders "$*"
fi
if [[ "$(type -p code)" != "" && "$USE_CODE_INSIDERS" == "" ]]; then
info "execing $(type -p code) with params: $*"
"$(type -p code)" "$*"
elif [[ $(type -p code-insiders) != "" ]]; then
info "execing $(type -p code-insiders) with params: $*"
"$(command -v code-insiders)" "$*"
else
echo "Either VS Code Stable or Insiders aren't installed on your system. Please visit"
echo "https://go.rtapp.tk/get-code to install VS Code. If you're using VS Code server,"
echo ""
return 1
fi
}