From 3d57e320145e3d566f960644745beaf789bb96d8 Mon Sep 17 00:00:00 2001 From: "Thomas A. Christensen II" <25492070+MillironX@users.noreply.github.com> Date: Tue, 24 Aug 2021 19:46:22 -0500 Subject: [PATCH] Move aliases to their own file --- dot_aliases | 30 ++++++++++++++++++++++++++++++ executable_dot_bashrc | 1 + executable_dot_zshrc | 36 +----------------------------------- 3 files changed, 32 insertions(+), 35 deletions(-) create mode 100644 dot_aliases diff --git a/dot_aliases b/dot_aliases new file mode 100644 index 0000000..7be42a7 --- /dev/null +++ b/dot_aliases @@ -0,0 +1,30 @@ +# Only create aliases if the underlying programs are available +# This allows portability between machines in different states +alias_if_exists () { + ALIAS=${1} + COMMAND=${2} + ARGS=${3} + if [ $(command -v $COMMAND) ]; then + if [ -n "$ARGS" ]; then + alias $ALIAS="$COMMAND $ARGS" + else + alias $ALIAS="$COMMAND" + fi + fi +} + +# Context-sensitive aliases +alias_if_exists config git '--git-dir=$HOME/.cfg/ --work-tree=$HOME' +alias_if_exists bat batcat +alias_if_exists cat bat +alias_if_exists ls lsd + +# Universal aliases +alias please='sudo $(fc -ln -1)' +alias nrun='__NV_PRIME_RENDER_OFFLOAD=1 __GLX_VENDOR_LIBRARY_NAME=nvidia __VK_LAYER_NV_optimus="NVIDIA_only"' + +# Alias-like functions +nd () { + mkdir "$1" + cd "$1" +} diff --git a/executable_dot_bashrc b/executable_dot_bashrc index 25ee6f8..76384db 100644 --- a/executable_dot_bashrc +++ b/executable_dot_bashrc @@ -16,6 +16,7 @@ export PATH # export SYSTEMD_PAGER= # User specific aliases and functions +source $HOME/.aliases # Make the prompt pretty, just in case we're stuck in bash land export PS1="[\[\e[32m\]\u\[\e[m\]@\[\e[33m\]\h\[\e[m\] \[\e[34m\]\W\[\e[m\]] \\$ " diff --git a/executable_dot_zshrc b/executable_dot_zshrc index 47b3aa9..b5b36be 100644 --- a/executable_dot_zshrc +++ b/executable_dot_zshrc @@ -127,56 +127,22 @@ if [ ! -n "$SSH_CONNECTION" ]; then ZLE_RPROMPT_INDENT=0 fi -# Personal aliases alias zshconfig="$EDITOR ~/.zshrc" -alias ohmyzsh="$EDITOR ~/.oh-my-zsh" -alias zshrefresh="source ~/.zshrc" - -# Dotfiles sync command -alias config='/usr/bin/git --git-dir=$HOME/.cfg/ --work-tree=$HOME' - -# Check for Ubuntu's name for bat -if [[ $(command -v batcat) ]]; then - alias bat="batcat" -fi +source $HOME/.aliases # Replace cat with bat if [[ $(command -v bat) ]]; then - alias cat="bat" export BAT_PAGER="less -RF" export MANPAGER="sh -c 'col -bx | bat -l man -p'" export MANROFFOPT="-c" fi -# Replace ls with lsd -if [[ $(command -v lsd) ]]; then - alias ls="lsd" -fi - # Add notification support for long-running processes if [[ $(command -v ntfy) ]]; then eval "$(ntfy shell-integration --longer-than 30)" export AUTO_NTFY_DONE_IGNORE="vim nano emacs zshconfig screen tmux ssh top htop less more most nethogs 'singularity shell' julia man" fi -# Replace VSCode with pure FOSS alternative -if [[ $(command -v codium) ]] && [[ ! $(command -v code) ]]; then - alias code="codium" -fi - -# Make forgetting sudo less painful -alias please='sudo $(fc -ln -1)' - -# Make and change directories in one easy step -# nd = New Directory -nd () { - mkdir "$1" - cd "$1" -} - -# Make running programs on the GPU less painful -alias nrun='__NV_PRIME_RENDER_OFFLOAD=1 __GLX_VENDOR_LIBRARY_NAME=nvidia __VK_LAYER_NV_optimus="NVIDIA_only"' - # Set the Nextflow enviroment caches export NXF_HOME="$HOME/.nextflow" export NXF_CONDA_CACHEDIR="$NXF_HOME/conda"