diff --git a/dots/.bash_aliases/all b/dots/.bash_aliases/all new file mode 100644 index 0000000..93bf1a9 --- /dev/null +++ b/dots/.bash_aliases/all @@ -0,0 +1,56 @@ +# shellcheck shell=bash +# vim: set ft=bash : + +alias ..="cd .." + +alias ls="ls --color=auto" +alias l="ls -1p" +alias ll="ls -lhp" +alias lt="ls -lhtp" +alias la="ls -lhap" +alias lta="ls -lhatp" +alias ldir="ls -dp" # list directories + +alias grep="grep --color=auto" + +alias rm="rm -I --preserve-root" +alias mv="mv -iv" +alias cp="cp -iv" +alias ln="ln -i" +alias mkdir="mkdir -pv" +alias chown="chown --preserve-root" +alias chmod="chmod --preserve-root" +alias chgrp="chgrp --preserve-root" + +alias ip="ip --color" +alias ipa="ip -brief address" +alias ipl="ip -brief link" +alias ipr="ip route" + +alias clip="xclip -sel clip" + +alias df="df -kTh" +alias fzfpac="pacman -Slq | fzf -m --preview 'pacman -Si {1}' | xargs -ro sudo pacman -S" +alias path='echo -e ${PATH//:/\\n}' # Pretty print path variables + +# Programs +alias o="xdg-open" +alias v="nvim" +alias g='git' +alias t=' task' +alias tsh='tasksh' +alias z='zathura --fork' +alias f='fzf' +alias fm='pcmanfm &>/dev/null &' +alias mm='micromamba' + +# Languages +alias r5="plt-r5rs --no-prim" +alias hs="ghci" +alias pl="swipl" +alias py="python" +alias r="R" + +alias azerty="setxkbmap be" +alias qwerty="setxkbmap us" +alias cole="setxkbmap us -variant colemak" diff --git a/dots/.bash_aliases/dualboot b/dots/.bash_aliases/dualboot new file mode 100644 index 0000000..96d394f --- /dev/null +++ b/dots/.bash_aliases/dualboot @@ -0,0 +1,16 @@ +# shellcheck shell=bash +# vim: set ft=bash : + +reboot-to-windows () +{ + # Check if grub is installed by checking if the command exists, if it does + # not, then assume that the system is using systemd-boot + if grub-install --version &>/dev/null; then + windows_title=$(grep -i windows /boot/grub/grub.cfg | cut -d "'" -f 2) + sudo grub-reboot "$windows_title" + echo "Grub set to reboot to Windows" + else + sudo bootctl set-oneshot windows.conf + echo "Systemd set to reboot to Windows" + fi +} diff --git a/dots/.bash_aliases/hosts/desktop-arch b/dots/.bash_aliases/hosts/desktop-arch new file mode 100644 index 0000000..63e7ebe --- /dev/null +++ b/dots/.bash_aliases/hosts/desktop-arch @@ -0,0 +1,7 @@ +# shellcheck shell=bash +# vim: set ft=bash : + +source "$HOME/.bash_aliases/dualboot" + +alias lm='ddcutil setvcp 10' +alias cuda-available='python -c "import torch; print(\"CUDA enabled:\", torch.cuda.is_available());"' diff --git a/dots/.bash_aliases/hosts/flex-arch b/dots/.bash_aliases/hosts/flex-arch new file mode 100644 index 0000000..7f5d621 --- /dev/null +++ b/dots/.bash_aliases/hosts/flex-arch @@ -0,0 +1,6 @@ +# shellcheck shell=bash +# vim: set ft=bash : + +source "$HOME/.bash_aliases/dualboot" + +alias lm='xbacklight -set' diff --git a/dots/.bash_aliases/jira b/dots/.bash_aliases/jira new file mode 100644 index 0000000..d8f4ac1 --- /dev/null +++ b/dots/.bash_aliases/jira @@ -0,0 +1,4 @@ +# shellcheck shell=bash +# vim: set ft=bash : + +alias jira-me='jira issue list -a$(jira me)' diff --git a/dots/.bash_aliases/lang-js b/dots/.bash_aliases/lang-js new file mode 100644 index 0000000..cf4117f --- /dev/null +++ b/dots/.bash_aliases/lang-js @@ -0,0 +1,35 @@ +# shellcheck shell=bash +# vim: set ft=bash : + +alias js="node" +alias ts="ts-node" + +yarn() { + if [[ -f "package-lock.json" ]]; then + echo "WARNING: package-lock.json exists" + read -p "Are you sure you want to run yarn? [y/N] " -n 1 -r + echo + if [[ $REPLY =~ ^[Yy]$ ]]; then + command yarn "$@" + else + echo "Aborted" + fi + else + command yarn "$@" + fi +} + +npm() { + if [[ -f "yarn.lock" ]]; then + echo "WARNING: yarn.lock exists" + read -p "Are you sure you want to run npm? [y/N] " -n 1 -r + echo + if [[ $REPLY =~ ^[Yy]$ ]]; then + command npm "$@" + else + echo "Aborted" + fi + else + command npm "$@" + fi +} diff --git a/dots/.bash_profile b/dots/.bash_profile new file mode 100644 index 0000000..f0807c0 --- /dev/null +++ b/dots/.bash_profile @@ -0,0 +1,10 @@ +# shellcheck shell=bash +# shellcheck disable=SC1090 +[[ -f ~/.bashrc ]] && . ~/.bashrc + +export SSH_AUTH_SOCK="${XDG_RUNTIME_DIR}/ssh-agent.socket" +export _JAVA_AWT_WM_NONREPARENTING=1 + +if [[ -z "${DISPLAY}" ]] && [[ "${XDG_VTNR}" -eq 1 ]]; then + exec startx "$HOME/.config/X11/xinitrc" >& ~/.xsession-errors +fi diff --git a/dots/.bashrc b/dots/.bashrc new file mode 100644 index 0000000..94a32dd --- /dev/null +++ b/dots/.bashrc @@ -0,0 +1,127 @@ +# shellcheck shell=bash +# shellcheck disable=SC1091,SC1090 +# If not running interactively, don't do anything +[[ $- != *i* ]] && return + +. /etc/os-release + +# Editor & prompt configuration +[ -f "$HOME/.bashrc.d/editor" ] && . "$HOME/.bashrc.d/editor" +[ -f "$HOME/.bashrc.d/prompt" ] && . "$HOME/.bashrc.d/prompt" + +# Aliases {{{ +# Load aliases dynamically +[ -f "$HOME/.bash_aliases/all" ] && . "$HOME/.bash_aliases/all" +[ -f "$HOME/.bash_aliases/hosts/$HOSTNAME" ] && . "$HOME/.bash_aliases/hosts/$HOSTNAME" +[ -f "$HOME/.bash_aliases/private" ] && . "$HOME/.bash_aliases/private" +[ -f "$HOME/.bash_aliases/lang-js" ] && . "$HOME/.bash_aliases/lang-js" +command -v jira >/dev/null && [ -f "$HOME/.bash_aliases/jira" ] && . "$HOME/.bash_aliases/jira" + +# Completions {{{ +[ -d "$HOME/.bash_completions" ] && for file in "$HOME/.bash_completions"/*; do + [ -f "$file" ] && . "$file" +done +# }}} + +# Host-specific and private configurations +[ -f "$HOME/.bashrc.d/hosts/$HOSTNAME" ] && . "$HOME/.bashrc.d/hosts/$HOSTNAME" +[ -f "$HOME/.bashrc.d/private" ] && . "$HOME/.bashrc.d/private" +# }}} + +# Prompt {{{ +[ -f "$HOME/.bashrc.d/prompt" ] && . "$HOME/.bashrc.d/prompt" +# }}} + +# Path {{{ +# Add ~/.bin to PATH +export PATH=~/.bin:$PATH +# }}} + +# History {{{ +export HISTSIZE=999999 +export HISTFILESIZE= # Unlimited +export HISTCONTROL=ignoreboth:erasedups +export HISTIGNORE=" *:clear:l:ls:cd" # Omit commands from history (e.g. those prepended with space) +# }}} + +# Man pages {{{ +# See `:h :Man` in NeoVim +export MANWIDTH=80 +export PAGER=nvimpager +# }}} + +# X11 {{{ +export XDG_SESSION_TYPE=X11 +export XDG_CONFIG_HOME=$HOME/.config +export XDG_DATA_HOME=$HOME/.local/share +# }}} + +# FZF {{{ +# Check if fzf is installed +if [ -f "/usr/bin/fzf" ]; then + # Fuzzy finder setup + export FZF_COMPLETION_TRIGGER='**' + export FZF_DEFAULT_COMMAND='ag -g ""' + export FZF_DEFAULT_OPTS=" + --pointer='❭' + --height 10% + --color=fg:-1,bg:-1" + export FZF_CTRL_T_COMMAND="${FZF_DEFAULT_COMMAND}" + export FZF_CTRL_T_OPTS="--preview='bat {} | head -500'" + + if [[ $ID == "raspbian" ]]; then + . /usr/share/doc/fzf/examples/completion.bash + . /usr/share/doc/fzf/examples/key-bindings.bash + elif [[ $ID == "arch" ]]; then + . /usr/share/fzf/completion.bash + . /usr/share/fzf/key-bindings.bash + fi + + _fzf_setup_completion path vim zathura xournalpp nvim mpv +else + echo "fzf not installed" +fi +# }}} + +# Go {{{ +export GOPATH="${XDG_DATA_HOME}/go" +# }}} + +# Jupyter {{{ +export JUPYTERLAB_DIR=$HOME/.local/share/jupyter/lab +# }}} + +# Conda {{{ +[ -f /opt/miniconda3/etc/profile.d/conda.sh ] && . /opt/miniconda3/etc/profile.d/conda.sh +# }}} + +# Zettelkasten {{{ +export ZK_PATH="$HOME/.zk" + +# SSH Agent {{{ +if [[ -z "${SSH_CONNECTION}" ]]; then + export SSH_AUTH_SOCK="$XDG_RUNTIME_DIR/ssh-agent.socket" +fi +# }}} + +# pnpm +export PNPM_HOME="/home/h/.local/share/pnpm" +case ":$PATH:" in + *":$PNPM_HOME:"*) ;; + *) export PATH="$PNPM_HOME:$PATH" ;; +esac +# pnpm end + +# Codi +# Usage: codi [filetype] [filename] +codi() { + local syntax="${1:-python}" + shift + nvim -c \ + "let g:startify_disable_at_vimenter = 1 |\ + set bt=nofile ls=0 noru nonu nornu |\ + hi ColorColumn ctermbg=NONE |\ + hi VertSplit ctermbg=NONE |\ + hi NonText ctermfg=0 |\ + Codi $syntax" "$@" +} diff --git a/dots/.bashrc.d/editor b/dots/.bashrc.d/editor new file mode 100644 index 0000000..fbf0a99 --- /dev/null +++ b/dots/.bashrc.d/editor @@ -0,0 +1,19 @@ +# shellcheck shell=bash +# vim: set ft=bash : + +# Set NeoVim as default editor +export EDITOR=nvim +export SUDO_EDITOR="$EDITOR" + +declare -A -r EDITOR_CONFIGS=( + ["nvim"]="$HOME/.config/nvim/init.lua" + ["vim"]="$HOME/.vimrc" +) + +edit_editor_config() { + for editor in "${!EDITOR_CONFIGS[@]}"; do + if [ "$EDITOR" = "$editor" ]; then + $EDITOR "${EDITOR_CONFIGS[$editor]}" + fi + done +} diff --git a/dots/.bashrc.d/hosts/desktop-arch b/dots/.bashrc.d/hosts/desktop-arch new file mode 100644 index 0000000..c0b612f --- /dev/null +++ b/dots/.bashrc.d/hosts/desktop-arch @@ -0,0 +1 @@ +# Desktop configuration diff --git a/dots/.bashrc.d/hosts/flex-arch b/dots/.bashrc.d/hosts/flex-arch new file mode 100644 index 0000000..66d4660 --- /dev/null +++ b/dots/.bashrc.d/hosts/flex-arch @@ -0,0 +1,19 @@ +# shellcheck shell=bash +# vim: set ft=bash : + +# >>> mamba initialize >>> +# !! Contents within this block are managed by 'mamba init' !! +export MAMBA_EXE="/usr/bin/micromamba"; +export MAMBA_ROOT_PREFIX="/home/h/.local/share/micromamba"; +__mamba_setup="$("$MAMBA_EXE" shell hook --shell bash --prefix "$MAMBA_ROOT_PREFIX" 2> /dev/null)" +if [ $? -eq 0 ]; then + eval "$__mamba_setup" +else + if [ -f "/home/h/.local/share/micromamba/etc/profile.d/micromamba.sh" ]; then + . "/home/h/.local/share/micromamba/etc/profile.d/micromamba.sh" + else + export PATH="/home/h/.local/share/micromamba/bin:$PATH" # extra space after export prevents interference from conda init + fi +fi +unset __mamba_setup +# <<< mamba initialize <<< diff --git a/dots/.bashrc.d/prompt b/dots/.bashrc.d/prompt new file mode 100644 index 0000000..a739826 --- /dev/null +++ b/dots/.bashrc.d/prompt @@ -0,0 +1,22 @@ +# shellcheck shell=bash +# vim: set ft=bash : + +get_branch_name() { + git symbolic-ref --quiet --short HEAD 2>/dev/null \ + || git rev-parse --short HEAD 2>/dev/null \ + || echo 'some branch' +} +get_git_info() { + git rev-parse --is-inside-work-tree &>/dev/null || return + echo -e "($(get_branch_name))" +} + +if [[ $SSH_CONNECTION ]]; then + PS1='\[\033[01;31m\]\u@\h\[\033[00m\] $(get_git_info)\W❭\[$(tput sgr0)\] ' +else + PS1='\u $(get_git_info)\W❭\[$(tput sgr0)\] ' +fi + +# Ellipsis when deep in directory +export PROMPT_DIRTRIM=2 +export PS1 diff --git a/dots/.bin/README.md b/dots/.bin/README.md new file mode 100644 index 0000000..6d87a64 --- /dev/null +++ b/dots/.bin/README.md @@ -0,0 +1,26 @@ +# Scripts + +Mostly tiny helper scripts & experiments, some more useful than others. + +## Setup + +Make sure the scripts are in your `$PATH` and executable. + +To add the complete directory of scripts to your `$PATH`: + +```bash +export PATH=~/.bin:$PATH +``` + +To make a any script `