~wrm/dotfiles

a8650b492e11f0460d938d6411faa1a2fe7c7424 — +wrm 4 months ago
Add shell (dash) config
3 files changed, 134 insertions(+), 0 deletions(-)

A .config/shell/aliasrc
A .config/shell/profile
A .config/shell/shellrc
A  => .config/shell/aliasrc +46 -0
@@ 1,46 @@
#!/bin/sh

alias vim="nvim"
alias vimdiff="nvim -d"
alias ls="ls -h --color=auto"
#alias locate="plocate"

remember () {
	DIR="$( realpath -s $1 )"
}
alias r="remember"
alias c='cd "$DIR"'

# fff - remember path on exit, sometimes we want to cd to it
f () {
	fff "$@"
	remember "$(cat "${XDG_CACHE_HOME}/fff/.fff_d")"
}

alias cfg="vim ${XDG_CONFIG_HOME}"
alias cfp="vim ${XDG_CONFIG_HOME}/shell/profile"
alias cfs="vim ${XDG_CONFIG_HOME}/shell/shellrc"
alias cfa="vim ${XDG_CONFIG_HOME}/shell/aliasrc"
alias cfx="vim ${XDG_CONFIG_HOME}/x11"
alias cfv="vim ${XDG_CONFIG_HOME}/nvim/init.vim"
alias cft="vim ${XDG_CONFIG_HOME}/tmux/tmux.conf"

alias startx="startx ${XDG_CONFIG_HOME}/x11/xinitrc"

alias yt="youtube-dl --add-metadata -i"
alias yta="yt -x -f bestaudio/best"

# TODO Auto gen these in profile for g, g~, etc.
alias g="git"
alias gs="git status"
alias ga="git add"
alias gc="git commit -S"
alias gm="git merge -S"
alias gd="git diff"
alias gr="git rebase"
alias gb="git branch"
alias gl="git log --show-signature"
alias gsl="git shortlog"
alias grl="git reflog"

alias g~="git --git-dir=$HOME/git/dotfiles/ --work-tree=$HOME"

A  => .config/shell/profile +34 -0
@@ 1,34 @@
#!/bin/sh

export EDITOR="nvim"
export BROWSER="links"

# XDG Dirs
export XDG_CONFIG_HOME="$HOME/.config"
export XDG_DATA_HOME="$HOME/.local/share"
export XDG_CACHE_HOME="$HOME/.cache"

# Shell environment
export PATH="${PATH}:$HOME/.local/bin"
export ENV="${XDG_CONFIG_HOME}/shell/shellrc"

# Uses \$ to delay expansion until string is actually shown.
# _ps1_dir is a function defined in $ENV.
export PS1="${USER}@$(cat /etc/hostname):\$(_ps1_dir)$ "
#export PS1="${USER}@$(cat /etc/hostname):.$ "
export HISTFILE="${XDG_DATA_HOME}/shell_history"
export HISTSIZE="9999999"

# Other Programs
export LESSHISTFILE="-"
export SUDO_ASKPASS="$HOME/.local/bin/dmenupass"
export WGETRC="$XDG_CONFIG_HOME/wget/wgetrc"
export TMUX_TMPDIR="$XDG_RUNTIME_DIR"
#export INPUTRC="${XDG_CONFIG_HOME}/shell/inputrc"
#export ALSA_CONFIG_PATH="$XDG_CONFIG_HOME/alsa/asoundrc"

# Convenients :)
export BAT="/sys/class/power_supply/BAT?"

# Run loadkeys in case we want to use the vterm
#loadkeys "${XDG_CONFIG_HOME}/conf.d/keymaps"

A  => .config/shell/shellrc +54 -0
@@ 1,54 @@
#!/bin/sh

# If we can use tmux and are not, attach to existing session or start new one.
# Also checks to be sure we are not in vconsole in case we want to startx.
# We do not exec because we want to be able to exit to sh.
if [ -z "${TMUX}" ] && [ -n "${DISPLAY}" ] && [ -x "$(command -v tmux)" ]; then
	{ tmux attach || tmux; } >/dev/null 2>&1
fi

# Disable ^s freezing interactive shells.
stty -ixon

_ps1_dir () {
	[ "$PWD" = "$HOME" ] && echo "~" || echo "$(basename "$PWD")"
}

if [ "${SHELL}" = "/bin/dash" ]; then
	set -V # vi mode

	# Write history on shell exit.
	trap 'fc -ln 0 >> ${HISTFILE}' EXIT

	# sudo !!, not expansion but good enough.
	alias s!!='sudo $(fc -ln -1)'

	# fc -s is broken in dash at the moment:
	# https://www.spinics.net/jists/dash/msg01797.html
	# So we hack around it.
	fcs () {
		if [ -z $1 ]; then
			eval $( fc -ln -1 )
			return
		fi

		old="${1%%=*}"
		if [ $old != "$1" ]; then
			new="${1#*=}"

			[ -z $2 ] && \
			eval $( fc -ln -1 | sed s/"$old"/"$new"/ ) || \
			eval $( fc -ln $2 $2 | sed s/"$old"/"$new"/ )
		else
			# NB keeping this line for posterity as funniest hack 2021.
			## Source from stdin to retain aliases.
			#fc -ln $1 $1 | . /dev/stdin
			eval $( fc -ln $1 $1 )
		fi
	}

fi

. "${XDG_CONFIG_HOME}/shell/aliasrc"

export GPG_TTY=$(tty)