From 06d1242317f7159ccf3014f0a1480e7c56236ebb Mon Sep 17 00:00:00 2001 From: Mohammad Reza Karimi Date: Sun, 4 Jan 2026 21:28:36 -0500 Subject: add all sorts of things --- bash/dot-config/bash/gentoo-color.bash | 6 +- bash/dot-config/bash/path.bash | 202 +++++++++++++++++++++++++++++++++ bash/dot-config/shellshort/bm-dirs | 0 bash/dot-config/shellshort/bm-files | 5 + bash/dot-config/shellshort/shortcutrc | 6 + 5 files changed, 215 insertions(+), 4 deletions(-) create mode 100644 bash/dot-config/bash/path.bash create mode 100644 bash/dot-config/shellshort/bm-dirs create mode 100644 bash/dot-config/shellshort/bm-files create mode 100644 bash/dot-config/shellshort/shortcutrc (limited to 'bash/dot-config') diff --git a/bash/dot-config/bash/gentoo-color.bash b/bash/dot-config/bash/gentoo-color.bash index f2a168d..a9abef8 100644 --- a/bash/dot-config/bash/gentoo-color.bash +++ b/bash/dot-config/bash/gentoo-color.bash @@ -2,9 +2,7 @@ # # source: https://gitweb.gentoo.org/repo/gentoo.git/plain/app-shells/bash/files/bashrc.d/10-gentoo-color-r2.bash # changes: -# - remove ls from the list of aliases (will configure it myself in bashrc) # - comment dircolor stuff at the end (don't like too many colors) -# - comment the unset gentoo_color, since I use it later for ls # # NOTE: copy this file for the root user and source it in its bashrc as well: # root # cp /home/moreka/.config/bash/gentoo-color.bash ~/.gentoo-color.bash @@ -61,7 +59,7 @@ fi if (( gentoo_color > 0 )); then # Colorize the output of diff(1), grep(1) and a few coreutils utilities. # However, do so only where no alias/function by the given name exists. - for _ in diff dir grep vdir; do + for _ in ls diff dir grep vdir; do if [[ $(type -t "$_") == file ]]; then alias "$_=$_ --color=auto" fi @@ -80,4 +78,4 @@ if (( gentoo_color > 0 )); then # fi fi -# unset -v gentoo_color +unset -v gentoo_color diff --git a/bash/dot-config/bash/path.bash b/bash/dot-config/bash/path.bash new file mode 100644 index 0000000..b4bcf55 --- /dev/null +++ b/bash/dot-config/bash/path.bash @@ -0,0 +1,202 @@ +#!/usr/bin/env bash +# +# Functions to modify colon separated variables like $PATH or $MANPATH +# +# Author: Dave Eddy +# Date: September 07, 2018 +# License: MIT +# Source: https://github.com/bahamas10/bash-path/blob/master/path.bash + +# +# path_add [direction] [varname] +# +# path_add takes a directory name, an optional direction name (defaults to +# "after" to append to list) and an optional variable name (defaults to PATH) +# and adds the directory name to data stored in variable. +# +# Example +# +# given: PATH='/bin:/sbin' +# +# path_add /usr/bin +# // PATH => '/bin:/sbin:/usr/bin' +# path_add /opt/local/bin before +# // PATH => '/opt/local/bin:/bin:/sbin:/usr/bin' +# +# The variable name should be passed by name. +# foo='' +# path_add /bin after foo +# // foo => '/bin' +# +path_add() { + local var=${3:-PATH} + local path= + path=$(path_print_add "$@") || return 1 + read -r "${var?}" <<< "$path" +} + +# +# path_remove [varname] +# +# path_remove takes a directory name and an optional variable name (defaults to +# PATH) and removes every instance of the directory name from the data stored in +# the variable. +# +# Example +# +# given: PATH='/bin:/sbin:/usr/bin:/usr/sbin' +# +# path_remove /usr/bin +# // PATH => '/bin:/sbin:/usr/sbin' +# path_remove /not-found +# // PATH => '/bin:/sbin:/usr/sbin' +# +# The variable name should be passed by name. +# foo='/bin:/sbin' +# path_remove /bin foo +# // foo => '/sbin' +# +path_remove() { + local var=${2:-PATH} + local path= + path=$(path_print_remove "$@") || return 1 + read -r "${var?}" <<< "$path" +} + +# +# path_clean [varname] +# +# path_clean takes an optional variable name (defaults to PATH) and "cleans" it, +# this process will: +# +# 1. Remove empty elements. +# 2. Remove relative directories. +# 3. Remove directories that don't exist/can't be accessed (checked with `cd`). +# 4. Remove duplicates (first element stays, subsequent elements are tossed). +# +# Example +# +# PATH='::/bin:/sbin:::./:../../some-path::/doesnt-exist' +# path_clean +# // PATH => '/bin:/sbin' + +# PATH='/bin:/bin//:////bin//////:/bin/dir/..::' +# path_clean +# // PATH => '/bin' +# +# The variable name should be passed by name. +# foo='/bin:/bin' +# path_clean /bin foo +# // foo => '/bin' +# +path_clean() { + local var=${1:-PATH} + local path= + path=$(path_print_clean "$@") || return 1 + read -r "${var?}" <<< "$path" +} + +# +# Exact same usage as path_add but prints the new PATH only and doesn't modify +# anything in place. +# +path_print_add() { + local p=$1 + local dir=${2:-after} + local var=${3:-PATH} + local arr + declare -A seen + + if [[ -z $p || $p == *:* ]]; then + echo "path_print_add: invalid argument: '$p'" >&2 + return 1 + fi + + IFS=: read -ra arr <<< "${!var}:" + + case "$dir" in + after) arr=("${arr[@]}" "$p");; + *) arr=("$p" "${arr[@]}");; + esac + + local IFS=: + echo "${arr[*]}" +} + +# +# Exact same usage as path_remove but prints the new PATH only and doesn't +# modify anything in place. +# +path_print_remove() { + local p=$1 + local var=${2:-PATH} + local arr + local newarr=() + declare -A seen + + if [[ -z $p || $p == *:* ]]; then + echo "path_print_remove: invalid argument: '$p'" >&2 + return 1 + fi + + IFS=: read -ra arr <<< "${!var}:" + + local _p + for _p in "${arr[@]}"; do + if [[ $p == "$_p" ]]; then + continue + fi + newarr+=("$_p") + done + + local IFS=: + echo "${newarr[*]}" +} + +# +# Exact same usage as path_clean but prints the new PATH only and doesn't +# modify anything in place. +# +path_print_clean() { + local var=${1:-PATH} + local arr + local newarr=() + declare -A seen + + # read PATH into an array, trailing ":" is due to: + # http://mywiki.wooledge.org/BashPitfalls#pf47 + IFS=: read -ra arr <<< "${!var}:" + + local p + for p in "${arr[@]}"; do + # Empty element is equivalent to CWD (weird, I know), remove it + if [[ -z $p ]]; then + continue + fi + + # Remove any relative paths + if [[ ${p:0:1} != '/' ]]; then + continue + fi + + # Normalize path and ensure we can access it + p=$(cd "$p" &>/dev/null && echo "$PWD") + + # Path doesn't exist or we can't access it + if [[ -z $p ]]; then + continue + fi + + # Filter out dups while we are here + if [[ -n ${seen[$p]} ]]; then + continue + fi + seen[$p]=true + + # Store the new path + newarr+=("$p") + done + + local IFS=: + echo "${newarr[*]}" +} diff --git a/bash/dot-config/shellshort/bm-dirs b/bash/dot-config/shellshort/bm-dirs new file mode 100644 index 0000000..e69de29 diff --git a/bash/dot-config/shellshort/bm-files b/bash/dot-config/shellshort/bm-files new file mode 100644 index 0000000..4e2b76d --- /dev/null +++ b/bash/dot-config/shellshort/bm-files @@ -0,0 +1,5 @@ +cala $XDG_CONFIG_HOME/alacritty/alacritty.toml +cgho $XDG_CONFIG_HOME/ghostty/config +cvim $XDG_CONFIG_HOME/nvim/init.lua +chy $XDG_CONFIG_HOME/hypr/hyprland.conf +cway $XDG_CONFIG_HOME/waybar/config.jsonc diff --git a/bash/dot-config/shellshort/shortcutrc b/bash/dot-config/shellshort/shortcutrc new file mode 100644 index 0000000..1eebef3 --- /dev/null +++ b/bash/dot-config/shellshort/shortcutrc @@ -0,0 +1,6 @@ +# vim: filetype=sh +alias cala="$EDITOR /home/moreka/.config/alacritty/alacritty.toml" \ +cgho="$EDITOR /home/moreka/.config/ghostty/config" \ +cvim="$EDITOR /home/moreka/.config/nvim/init.lua" \ +chy="$EDITOR /home/moreka/.config/hypr/hyprland.conf" \ +cway="$EDITOR /home/moreka/.config/waybar/config.jsonc" \ -- cgit v1.2.3-71-gdd5e