Add quality of life improvements to different parts of my config

THis include fixing filenames for konsole because
the whole repo can't be checked out on Windows, migrating some directories into
the config folder and even a bit of cleanup.

Signed-off-by: Andrei Jiroh Eugenio Halili <ajhalili2006@gmail.com>
This commit is contained in:
Andrei Jiroh Halili 2022-08-22 23:16:16 +08:00
parent c4319bfc77
commit c24a45b485
No known key found for this signature in database
GPG Key ID: D4A928E0527DB795
14 changed files with 148 additions and 101 deletions

View File

@ -1,5 +0,0 @@
#!/bin/bash
if [[ -f "/snap/bin/code" ]]; then
exec /snap/bin/code $*
fi

View File

@ -1,17 +0,0 @@
#!/bin/env bash
echo "---> Refreshing custom functions..."
sleep 5
# change the path if it's different
source ~/.dotfiles/bashrc/worthwhile-functions
if [[ $? == 0 ]]; then
echo "info: Successfully refreshed functions to current session."
echo "info: Something don't work? Run edit-funcs-bashrc to edit"
echo "info: or even remove problematic functions"
else
echo "! Problems found, please run edit-funcs-bashrc to fix"
echo " and re-run this command again. In case of path changes,"
echo " please do 'source ~/.bashrc' if issue presists."
echo " If you ever moved that file, also update your ~/.bashrc and"
echo " the ~/.dotfiles/bin/reload-funcs-bashrc\#L5"
fi

View File

@ -1,9 +1,8 @@
#!/bin/env sh
SUDO_PATH=$(command -v sudo)
SU_PATH=$(command -v su)
SUDO=${SUDO:-"sudo"}
if [ "$1" = "" -o "$1" = "help" ]; then
if [ "$1" = "" ] || [ "$1" = "help" ]; then
echo "Usage: [sudo|su root -] $0 COMMAND [ARG]"
echo "Permanently installs your .dotfiles/bin scripts into your system for"
echo "all users. These system-wide installs are on /usr/local/bin/dotfiles-bin"
@ -36,11 +35,11 @@ if [ "$1" = "" -o "$1" = "help" ]; then
exit 0
fi
if [ $@ = "status" ]; then
if [ ! $DOTFILES_SYS_INSTALL_PATH = "" ]; then
if [ "$1" = "status" ]; then
if [ "! $DOTFILES_SYS_INSTALL_PATH" = "" ]; then
echo "Local install: $DOTFILES_SYS_INSTALL_PATH"
elif [ -f "$HOME/.dotfiles/config/sysbin-path" ]; then
DOTFILES_SYS_IBSTALL_PATH=$(cat "$HOME/.dotfiles/config/sysbin-path")
DOTFILES_SYS_INSTALL_PATH=$(cat "$HOME/.dotfiles/config/sysbin-path")
echo "Local install: $DOTFILES_SYS_INSTALL_PATH"
else
echo "Local install: ✖ Not found"

View File

@ -2,5 +2,5 @@
# these commands should be triggered on shell startup
source "$DOTFILES_HOME/config/bashrc/aliases"
source "$DOTFILES_HOME/config/bashrc/worthwhile-functions"
source "$DOTFILES_HOME/config/bashrc/functions"
#guild-test

86
config/bashrc/functions Normal file
View File

@ -0,0 +1,86 @@
#!/bin/bash
# shellcheck disable=SC2199,SC2068,SC1091,SC2086,SC2145
# custom function management here
# changes to the worthwhile-functions filepath requires
# an update o the filepath via 'edit-script reload-funcs-bashrc
# and also any reference here
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/worthwhile-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 "$(command -v $1)"
}
# reloading stuff
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."
}
code() {
# quick trick in case only code-insiders is installed and not code
if ! command -v code >> /dev/null; then
if command -v code-insiders >>/dev/null; then
warn "code-stable is not installed, but code-insiders is found in PATH, setting USE_CODE_INSIDERS"
warn "for this run"
USE_CODE_INSIDERS=true
fi
fi
if [[ -f "/snap/bin/code" && "$USE_CODE_INSIDERS" == "" ]]; then
echo "info: execing /snap/bin/code with params: $*"
exec /snap/bin/code "$@"
elif [[ -f "/snap/bin/code-insiders" ]]; then
echo "info: execing /snap/bin/code-insiders with params: $*"
exec /snap/bin/code-insiders "$*"
fi
if [[ "$(command -v code)" != "" && "$USE_CODE_INSIDERS" == "" ]]; then
info "execing $(command -v code) with params: $*"
exec "$(command -v code)" "$*"
elif [[ $(command -v code-insiders) != "" ]]; then
info "execing $(command -v code-insiders) with params: $*"
exec "$(command -v code-insiders)" "$*"
fi
echo "Either VS Code Stable or Insiders aren't installed on your system. Please visit"
echo "https://go.rtapp.tk/get-code to install the code editor."
return 1
}

View File

@ -5,11 +5,30 @@
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
# for examples
############################################################################
# https://packaging.ubuntu.com/html/getting-set-up.html#configure-your-shell
export DEBFULLNAME="Andrei Jiroh Halili"
# Temporary Gmail address for devel stuff, even through my longer email one is, well,
# on my public GPG key btw, so YOLO it.
export DEBEMAIL="ajhalili2006@gmail.com"
## Update path and inject some vars before the shell interactivity checks ##
export DOTFILES_HOME="$HOME/.dotfiles"
export DOTFILES_STUFF_BIN="$DOTFILES_HOME/bin"
export PATH="$HOME/.local/bin:$HOME/.cargo/bin:$DOTFILES_STUFF_BIN:$PATH"
## Add homebrew to path ##
test -d /home/linuxbrew/.linuxbrew && eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"
test -d $HOME/.linuxbrew && eval $($HOME/.linuxbrew/bin/brew shellenv)
############################################################################
# If not running interactively, don't do anything
#case $- in
# *i*) ;;
# *) return;;
#esac
case $- in
*i*) ;;
*) return;;
esac
# don't put duplicate lines or lines starting with space in the history.
# See bash(1) for more options
@ -127,12 +146,6 @@ export NVM_DIR="$HOME/.nvm"
# Deta CLI
export PATH="$HOME/.deta/bin:$PATH"
# scripts in ~/.local/bin and ~/.dotfiles/bin
# also $HOME/.cargo/bin
export DOTFILES_HOME="$HOME/.dotfiles"
export DOTFILES_STUFF_BIN="$DOTFILES_HOME/bin"
export PATH="$HOME/.local/bin:$HOME/.cargo/bin:$DOTFILES_STUFF_BIN:$PATH"
# use nano instead of vi by default when on SSH
# for git, there's the option of firing up VS Code, if you prefered.
#export VISUAL="code --wait"
@ -170,18 +183,8 @@ fi
# autocompletion for GitHub CLI
eval "$(gh completion -s bash)"
# custom aliases and functions I made
# sorucing through the chain-source script
source "$DOTFILES_HOME/config/bashrc/chain-source" # TODO: Remove guild-test stuff
# https://packaging.ubuntu.com/html/getting-set-up.html#configure-your-shell
export DEBFULLNAME="Andrei Jiroh Halili"
# Temporary Gmail address for devel stuff, even through my longer email one is, well,
# on my public GPG key btw, so YOLO it.
export DEBEMAIL="ajhalili2006@gmail.com"
# Homebrew
test -d /home/linuxbrew/.linuxbrew && eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"
# Source both the custom aliases and shell functions in one go
source "$DOTFILES_HOME/config/bashrc/chain-source"
# Golang, probably we need to tweak this btw
export PATH="$HOME/go/bin:$PATH" GOPATH="$HOME/go"

View File

@ -1,48 +0,0 @@
#!/bin/bash
# shellcheck disable=SC2199,SC2068,SC1091,SC2086,SC2145
# custom function management here
# changes to the worthwhile-functions filepath requires
# an update o the filepath via 'edit-script reload-funcs-bashrc
# and also any reference here
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/worthwhile-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 "$(command -v $1)"
}
# reloading stuff
refresh-funcs() {
"$DOTFILES_STUFF_BIN/reload-funcs-bashrc"
}
refresh-aliases() {
source "$HOME/.dotfiles/bashrc/aliases"
}
# https://commentedcode.org/blog/2020/09/21/changing-default-branch-of-git-init/
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."
}

View File

@ -1,7 +1,9 @@
#!/usr/bin/env bash
#shellcheck disable=SC2034
# Library code for the bootstrap scripts
# Adding colors to some text in termnial based on checks
# NO_COLOR: https://no-color.org/
if [ -t 1 ] && [[ "$NO_COLOR" == "" ]]; then
RED=$(printf '\033[31m')
GREEN=$(printf '\033[32m')
@ -18,4 +20,24 @@ else
MAGENTA=""
BOLD=""
RESET=""
fi
fi
error() {
echo "${RED}error: $*${RESET}"
}
success() {
echo "${GREEN}success: $*${RESET}"
}
warn() {
echo "${YELLOW}warning: $*${RESET}"
}
info() {
echo "${BOLD}info: $*${RESET}"
}
showStage() {
echo "${BOLD}==> $*${RESET}"
}

View File

@ -1,9 +1,16 @@
#!/usr/bin/env bash
source "$(dirname $0)/00-script-library.sh"
stage "Symlinking shell configuration files..."
if [[ $DOTFILES_OS_NAME == "android-termux" ]]; then
if [ ! -f "$HOME/.bashrc" ]; then
ln -s $HOME/.dotfiles/termux.bashrc ~/.bashrc
ln -s "$HOME/.dotfiles/termux.bashrc" ~/.bashrc
elif [ -f "$HOME/.bashrc" ]; then
cp "$HOME/.bashrc" "$HOME/.bashrc.bak"
ln -s "$HOME/.dotfiles/termux.bashrc" ~/.bashrc
fi
elif [[ $DOTFILES_OS_NAME == "debian" ]] || [[ $DOTFILES_OS_NAME == "ubuntu" ]]; then
if [[ $SKIP_CONFIG_LINKING == "" ]] && [ ! -f "$HOME/.bashrc" ]; then
ln -s "$HOME/.dotfiles/ubuntu.bashrc" ~/.bashrc