feat: add bash configs
This commit is contained in:
parent
fd258a4df3
commit
6ee9a85ca1
7 changed files with 275 additions and 0 deletions
21
bash/.bashrc
Normal file
21
bash/.bashrc
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
# ~/.bashrc
|
||||||
|
|
||||||
|
[[ $- != *i* ]] && return
|
||||||
|
|
||||||
|
BASH_CONFIG_DIR="${XDG_CONFIG_HOME:-$HOME/.config}/bash"
|
||||||
|
|
||||||
|
for config in \
|
||||||
|
env \
|
||||||
|
aliases \
|
||||||
|
build \
|
||||||
|
perf \
|
||||||
|
systemd \
|
||||||
|
tools
|
||||||
|
do
|
||||||
|
file="$BASH_CONFIG_DIR/$config.bash"
|
||||||
|
[[ -r "$file" ]] && source "$file"
|
||||||
|
done
|
||||||
|
|
||||||
|
# Machine/private configuration.
|
||||||
|
[[ -r "$BASH_CONFIG_DIR/local.bash" ]] &&
|
||||||
|
source "$BASH_CONFIG_DIR/local.bash"
|
||||||
20
bash/aliases.bash
Normal file
20
bash/aliases.bash
Normal file
|
|
@ -0,0 +1,20 @@
|
||||||
|
if command -v eza &>/dev/null; then
|
||||||
|
alias ls='eza -1 --icons'
|
||||||
|
alias ll='eza -la --icons'
|
||||||
|
alias la='eza -a --icons'
|
||||||
|
alias l='eza --icons'
|
||||||
|
else
|
||||||
|
alias ll='ls -alF'
|
||||||
|
alias la='ls -A'
|
||||||
|
alias l='ls -CF'
|
||||||
|
fi
|
||||||
|
|
||||||
|
alias lsf='ls -p | grep -v /'
|
||||||
|
|
||||||
|
alias grep='grep --color=auto'
|
||||||
|
alias fgrep='fgrep --color=auto'
|
||||||
|
alias egrep='egrep --color=auto'
|
||||||
|
|
||||||
|
alias alert='notify-send --urgency=low \
|
||||||
|
-i "$([ $? = 0 ] && echo terminal || echo error)" \
|
||||||
|
"$(history | tail -n1 | sed -e '\''s/^\s*[0-9]\+\s*//;s/[;&|]\s*alert$//'\'')"'
|
||||||
101
bash/build.bash
Normal file
101
bash/build.bash
Normal file
|
|
@ -0,0 +1,101 @@
|
||||||
|
_builddir_for() {
|
||||||
|
case "$1" in
|
||||||
|
debug)
|
||||||
|
printf '%s\n' "${BUILDDIR_DEBUG:-builddir-debug}"
|
||||||
|
;;
|
||||||
|
release)
|
||||||
|
printf '%s\n' "${BUILDDIR_RELEASE:-builddir-release}"
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo "Unknown build type: $1" >&2
|
||||||
|
return 2
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
|
_ensure_builddir() {
|
||||||
|
local type="$1"
|
||||||
|
local dir
|
||||||
|
local native_args=()
|
||||||
|
|
||||||
|
dir="$(_builddir_for "$type")" || return
|
||||||
|
|
||||||
|
if [[ -f native.ini ]]; then
|
||||||
|
native_args+=(--native-file native.ini)
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ ! -f "$dir/meson-private/coredata.dat" ]]; then
|
||||||
|
echo "Configuring Meson $type build in '$dir'..." >&2
|
||||||
|
|
||||||
|
meson setup "$dir" \
|
||||||
|
--buildtype="$type" \
|
||||||
|
"${native_args[@]}" >&2 || return
|
||||||
|
fi
|
||||||
|
|
||||||
|
printf '%s\n' "$dir"
|
||||||
|
}
|
||||||
|
|
||||||
|
_nic() {
|
||||||
|
local type="$1"
|
||||||
|
shift
|
||||||
|
|
||||||
|
local dir
|
||||||
|
dir="$(_ensure_builddir "$type")" || return
|
||||||
|
|
||||||
|
ninja -C "$dir" "$@"
|
||||||
|
}
|
||||||
|
|
||||||
|
nic() {
|
||||||
|
_nic "${BUILD_TYPE:-debug}" "$@"
|
||||||
|
}
|
||||||
|
|
||||||
|
nic-debug() {
|
||||||
|
_nic debug "$@"
|
||||||
|
}
|
||||||
|
|
||||||
|
nic-release() {
|
||||||
|
_nic release "$@"
|
||||||
|
}
|
||||||
|
|
||||||
|
nit() {
|
||||||
|
if (($# == 0)); then
|
||||||
|
echo "usage: nit <target> [args...]" >&2
|
||||||
|
return 2
|
||||||
|
fi
|
||||||
|
|
||||||
|
local target="$1"
|
||||||
|
local type="${BUILD_TYPE:-debug}"
|
||||||
|
local dir
|
||||||
|
|
||||||
|
shift
|
||||||
|
|
||||||
|
dir="$(_ensure_builddir "$type")" || return
|
||||||
|
|
||||||
|
ninja -C "$dir" "$target" || return
|
||||||
|
"$dir/$target" "$@"
|
||||||
|
}
|
||||||
|
|
||||||
|
nicc() {
|
||||||
|
if (($# == 0)); then
|
||||||
|
echo "usage: nicc <target> [ninja args...]" >&2
|
||||||
|
return 2
|
||||||
|
fi
|
||||||
|
|
||||||
|
local target="$1"
|
||||||
|
local type="${BUILD_TYPE:-debug}"
|
||||||
|
local dir
|
||||||
|
local filename
|
||||||
|
|
||||||
|
shift
|
||||||
|
|
||||||
|
dir="$(_ensure_builddir "$type")" || return
|
||||||
|
filename="${target##*/}"
|
||||||
|
|
||||||
|
ninja -C "$dir" "$target" "$@" || return
|
||||||
|
|
||||||
|
install -Dm755 \
|
||||||
|
"$dir/$target" \
|
||||||
|
"$HOME/.local/bin/$filename" || return
|
||||||
|
|
||||||
|
"$filename" --version
|
||||||
|
}
|
||||||
37
bash/env.bash
Normal file
37
bash/env.bash
Normal file
|
|
@ -0,0 +1,37 @@
|
||||||
|
export TERM=xterm-256color
|
||||||
|
|
||||||
|
path_prepend() {
|
||||||
|
[[ -d "$1" ]] || return
|
||||||
|
case ":$PATH:" in
|
||||||
|
*":$1:"*) ;;
|
||||||
|
*) PATH="$1:$PATH" ;;
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
|
path_append() {
|
||||||
|
[[ -d "$1" ]] || return
|
||||||
|
case ":$PATH:" in
|
||||||
|
*":$1:"*) ;;
|
||||||
|
*) PATH="$PATH:$1" ;;
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
|
path_prepend "$HOME/.local/bin"
|
||||||
|
path_prepend "${GOBIN:-${GOPATH:-$HOME/go}/bin}"
|
||||||
|
path_prepend "$HOME/.cargo/bin"
|
||||||
|
path_prepend "$HOME/.ghcup/bin"
|
||||||
|
path_prepend "$HOME/gitui"
|
||||||
|
path_append "$HOME/Git/FlameGraph"
|
||||||
|
path_append "$HOME/.fzf/bin"
|
||||||
|
|
||||||
|
export PATH
|
||||||
|
|
||||||
|
export FZF_DEFAULT_COMMAND='fd --type file'
|
||||||
|
export FZF_CTRL_T_COMMAND="$FZF_DEFAULT_COMMAND"
|
||||||
|
|
||||||
|
HISTCONTROL=ignoreboth
|
||||||
|
HISTSIZE=10000
|
||||||
|
HISTFILESIZE=20000
|
||||||
|
|
||||||
|
shopt -s histappend
|
||||||
|
shopt -s checkwinsize
|
||||||
35
bash/perf.bash
Normal file
35
bash/perf.bash
Normal file
|
|
@ -0,0 +1,35 @@
|
||||||
|
alias perf-rec='perf record -g -e cpu-cycles -p'
|
||||||
|
alias perf-rep='perf report'
|
||||||
|
|
||||||
|
perf-dat() {
|
||||||
|
perf script | stackcollapse-perf.pl > "$1"
|
||||||
|
}
|
||||||
|
|
||||||
|
flamegraph() {
|
||||||
|
local perf_name="${1:-pdat}"
|
||||||
|
|
||||||
|
[[ -f perf.data ]] || {
|
||||||
|
echo "perf.data not found" >&2
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
|
mkdir -p img
|
||||||
|
|
||||||
|
perf-dat "$perf_name" &&
|
||||||
|
flamegraph.pl "$perf_name" > "img/$perf_name.svg"
|
||||||
|
}
|
||||||
|
|
||||||
|
flamegraph-diff() {
|
||||||
|
if [[ -f "$1" && -f "$2" ]]; then
|
||||||
|
mkdir -p img
|
||||||
|
difffolded.pl "$1" "$2" |
|
||||||
|
flamegraph.pl > "img/perf-diff-$1-$2.svg"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
binlog-dump() {
|
||||||
|
barsic dump \
|
||||||
|
--prefix="$1" \
|
||||||
|
--no-start-echo \
|
||||||
|
-- binlog-dumper --module "$2"
|
||||||
|
}
|
||||||
27
bash/systemd.bash
Normal file
27
bash/systemd.bash
Normal file
|
|
@ -0,0 +1,27 @@
|
||||||
|
set-scope() {
|
||||||
|
local scope="${1:-default-scope}"
|
||||||
|
|
||||||
|
systemd-run \
|
||||||
|
--user \
|
||||||
|
--scope \
|
||||||
|
--unit="$scope" \
|
||||||
|
bash
|
||||||
|
}
|
||||||
|
|
||||||
|
check-scope() {
|
||||||
|
local scope="${1:-default-scope}"
|
||||||
|
|
||||||
|
systemctl --user status "$scope.scope"
|
||||||
|
}
|
||||||
|
|
||||||
|
shtop() {
|
||||||
|
local scope="${1:-default-scope.scope}"
|
||||||
|
local cg
|
||||||
|
|
||||||
|
cg=$(systemctl --user show \
|
||||||
|
"$scope" \
|
||||||
|
-p ControlGroup \
|
||||||
|
--value) || return
|
||||||
|
|
||||||
|
htop -p "$(paste -sd, "/sys/fs/cgroup${cg}/cgroup.procs")"
|
||||||
|
}
|
||||||
34
bash/tools.bash
Normal file
34
bash/tools.bash
Normal file
|
|
@ -0,0 +1,34 @@
|
||||||
|
# bash-completion
|
||||||
|
if ! shopt -oq posix; then
|
||||||
|
if [[ -r /usr/share/bash-completion/bash_completion ]]; then
|
||||||
|
source /usr/share/bash-completion/bash_completion
|
||||||
|
elif [[ -r /etc/bash_completion ]]; then
|
||||||
|
source /etc/bash_completion
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# ble.sh
|
||||||
|
[[ -r "$HOME/.local/share/blesh/out/ble.sh" ]] &&
|
||||||
|
source "$HOME/.local/share/blesh/out/ble.sh"
|
||||||
|
|
||||||
|
# NVM
|
||||||
|
export NVM_DIR="$HOME/.nvm"
|
||||||
|
|
||||||
|
[[ -s "$NVM_DIR/nvm.sh" ]] &&
|
||||||
|
source "$NVM_DIR/nvm.sh"
|
||||||
|
|
||||||
|
[[ -s "$NVM_DIR/bash_completion" ]] &&
|
||||||
|
source "$NVM_DIR/bash_completion"
|
||||||
|
|
||||||
|
# Shell integrations
|
||||||
|
command -v starship &>/dev/null &&
|
||||||
|
eval "$(starship init bash)"
|
||||||
|
|
||||||
|
command -v zoxide &>/dev/null &&
|
||||||
|
eval "$(zoxide init bash)"
|
||||||
|
|
||||||
|
command -v atuin &>/dev/null &&
|
||||||
|
eval "$(atuin init bash)"
|
||||||
|
|
||||||
|
command -v direnv &>/dev/null &&
|
||||||
|
eval "$(direnv hook bash)"
|
||||||
Loading…
Add table
Add a link
Reference in a new issue