From 81b617ea264aeebda021f470412ff1b4cec3bbc7 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Sun, 1 Jun 2025 11:56:03 +0200 Subject: [PATCH] Add bash configuration --- default/bash/aliases | 27 +++++++++++++ default/bash/envs | 3 ++ default/bash/functions | 79 +++++++++++++++++++++++++++++++++++++++ default/bash/init | 16 ++++++++ default/bash/inputrc | 41 ++++++++++++++++++++ default/bash/prompt | 7 ++++ default/bash/rc | 6 +++ default/bash/shell | 12 ++++++ install/configurations.sh | 3 ++ 9 files changed, 194 insertions(+) create mode 100644 default/bash/aliases create mode 100644 default/bash/envs create mode 100644 default/bash/functions create mode 100644 default/bash/init create mode 100644 default/bash/inputrc create mode 100644 default/bash/prompt create mode 100644 default/bash/rc create mode 100644 default/bash/shell diff --git a/default/bash/aliases b/default/bash/aliases new file mode 100644 index 0000000..f43a6f4 --- /dev/null +++ b/default/bash/aliases @@ -0,0 +1,27 @@ +# File system +alias ls='eza -lh --group-directories-first --icons=auto' +alias lsa='ls -a' +alias lt='eza --tree --level=2 --long --icons --git' +alias lta='lt -a' +alias ff="fzf --preview 'batcat --style=numbers --color=always {}'" +alias fd='fdfind' +# alias cd='zoxide' + +# Directories +alias ..='cd ..' +alias ...='cd ../..' +alias ....='cd ../../..' + +# Tools +alias n='nvim' +alias g='git' +alias d='docker' +alias r='rails' +alias bat='batcat' +alias lzg='lazygit' +alias lzd='lazydocker' + +# Git +alias gcm='git commit -m' +alias gcam='git commit -a -m' +alias gcad='git commit -a --amend' diff --git a/default/bash/envs b/default/bash/envs new file mode 100644 index 0000000..2494d70 --- /dev/null +++ b/default/bash/envs @@ -0,0 +1,3 @@ +# Editor used by CLI +export EDITOR="nvim" +export SUDO_EDITOR="$EDITOR" diff --git a/default/bash/functions b/default/bash/functions new file mode 100644 index 0000000..5c2b6af --- /dev/null +++ b/default/bash/functions @@ -0,0 +1,79 @@ +# Compression +compress() { tar -czf "${1%/}.tar.gz" "${1%/}"; } +alias decompress="tar -xzf" + +# Convert webm files generated by the Gnome screenshot video recorder to mp4s that are more compatible +webm2mp4() { + input_file="$1" + output_file="${input_file%.webm}.mp4" + ffmpeg -i "$input_file" -c:v libx264 -preset slow -crf 22 -c:a aac -b:a 192k "$output_file" +} + +# Write iso file to sd card +iso2sd() { + if [ $# -ne 2 ]; then + echo "Usage: iso2sd " + echo "Example: iso2sd ~/Downloads/ubuntu-25.04-desktop-amd64.iso /dev/sda" + echo -e "\nAvailable SD cards:" + lsblk -d -o NAME | grep -E '^sd[a-z]' | awk '{print "/dev/"$1}' + else + sudo dd bs=4M status=progress oflag=sync if="$1" of="$2" + sudo eject $2 + fi +} + +# Create a desktop launcher for a web app +web2app() { + if [ "$#" -ne 3 ]; then + echo "Usage: web2app (IconURL must be in PNG -- use https://dashboardicons.com)" + return 1 + fi + + local APP_NAME="$1" + local APP_URL="$2" + local ICON_URL="$3" + local ICON_DIR="$HOME/.local/share/applications/icons" + local DESKTOP_FILE="$HOME/.local/share/applications/${APP_NAME}.desktop" + local ICON_PATH="${ICON_DIR}/${APP_NAME}.png" + + mkdir -p "$ICON_DIR" + + if ! curl -sL -o "$ICON_PATH" "$ICON_URL"; then + echo "Error: Failed to download icon." + return 1 + fi + + cat > "$DESKTOP_FILE" <" + return 1 + fi + + local APP_NAME="$1" + local ICON_DIR="$HOME/.local/share/applications/icons" + local DESKTOP_FILE="$HOME/.local/share/applications/${APP_NAME}.desktop" + local ICON_PATH="${ICON_DIR}/${APP_NAME}.png" + + rm "$DESKTOP_FILE" + rm "$ICON_PATH" +} + +# Ensure that external keyboards that use an fn key has the F keys as the default +alias fix_fkeys='echo 2 | sudo tee /sys/module/hid_apple/parameters/fnmode' diff --git a/default/bash/init b/default/bash/init new file mode 100644 index 0000000..8f4d84c --- /dev/null +++ b/default/bash/init @@ -0,0 +1,16 @@ +if command -v mise &> /dev/null; then + eval "$(mise activate bash)" +fi + +if command -v zoxide &> /dev/null; then + eval "$(zoxide init bash)" +fi + +if command -v fzf &> /dev/null; then + if [[ -f /usr/share/bash-completion/completions/fzf ]]; then + source /usr/share/bash-completion/completions/fzf + fi + if [[ -f /usr/share/doc/fzf/examples/key-bindings.bash ]]; then + source /usr/share/doc/fzf/examples/key-bindings.bash + fi +fi diff --git a/default/bash/inputrc b/default/bash/inputrc new file mode 100644 index 0000000..6e4bb8a --- /dev/null +++ b/default/bash/inputrc @@ -0,0 +1,41 @@ +set meta-flag on +set input-meta on +set output-meta on +set convert-meta off +set completion-ignore-case on +set completion-prefix-display-length 2 +set show-all-if-ambiguous on +set show-all-if-unmodified on + +# Arrow keys match what you've typed so far against your command history +"\e[A": history-search-backward +"\e[B": history-search-forward +"\e[C": forward-char +"\e[D": backward-char + +# Immediately add a trailing slash when autocompleting symlinks to directories +set mark-symlinked-directories on + +# Do not autocomplete hidden files unless the pattern explicitly begins with a dot +set match-hidden-files off + +# Show all autocomplete results at once +set page-completions off + +# If there are more than 200 possible completions for a word, ask to show them all +set completion-query-items 200 + +# Show extra file information when completing, like `ls -F` does +set visible-stats on + +$if Bash + # Be more intelligent when autocompleting by also looking at the text after + # the cursor. For example, when the current line is "cd ~/src/mozil", and + # the cursor is on the "z", pressing Tab will not autocomplete it to "cd + # ~/src/mozillail", but to "cd ~/src/mozilla". (This is supported by the + # Readline used by Bash 4.) + set skip-completed-text on + + # Coloring for Bash 4 tab completions. + set colored-stats on +$endif diff --git a/default/bash/prompt b/default/bash/prompt new file mode 100644 index 0000000..4901a58 --- /dev/null +++ b/default/bash/prompt @@ -0,0 +1,7 @@ +# Technicolor dreams +force_color_prompt=yes +color_prompt=yes + +# Simple prompt with path in the window/pane title and caret for typing line +PS1=$'\uf0a9 ' +PS1="\[\e]0;\w\a\]$PS1" diff --git a/default/bash/rc b/default/bash/rc new file mode 100644 index 0000000..6c9e1d2 --- /dev/null +++ b/default/bash/rc @@ -0,0 +1,6 @@ +source ~/.local/share/omarchy/default/bash/shell +source ~/.local/share/omarchy/default/bash/aliases +source ~/.local/share/omarchy/default/bash/functions +source ~/.local/share/omarchy/default/bash/prompt +source ~/.local/share/omarchy/default/bash/init +source ~/.local/share/omarchy/default/bash/envs diff --git a/default/bash/shell b/default/bash/shell new file mode 100644 index 0000000..7fb450d --- /dev/null +++ b/default/bash/shell @@ -0,0 +1,12 @@ +# History control +shopt -s histappend +HISTCONTROL=ignoreboth +HISTSIZE=32768 +HISTFILESIZE="${HISTSIZE}" + +# Autocompletion +# source /usr/share/bash-completion/bash_completion + +# Set complete path +export PATH="./bin:$HOME/.local/bin:$PATH" +set +h diff --git a/install/configurations.sh b/install/configurations.sh index 6593316..1ffb44b 100644 --- a/install/configurations.sh +++ b/install/configurations.sh @@ -5,5 +5,8 @@ rm -rf ~/.config/nvim/.git # Copy over Omarchy configs cp -R ~/.local/share/omarchy/config/* ~/.config/ +# Use default bashrc from Omarchy +echo "source ~/.local/share/omarchy/default/bash/rc" >~/.bashrc + # Turn off relative line numbers in nvim echo "vim.opt.relativenumber = false" >>~/.config/nvim/lua/config/options.lua