Compare commits

..

No commits in common. "10c415c3e5d90f462d31a669ce719b0a091001b9" and "70f4f215c07ee582329c96e33c31d02e90f5e3af" have entirely different histories.

View file

@ -1,70 +1,66 @@
{ pkgs, ... }:
{ ... }:
{
programs.bash = {
enable = true;
enableCompletion = false;
initExtra = ''
if [[ ! -v BASH_COMPLETION_VERSINFO ]] &&
[[ -f "${pkgs.bash-completion}/etc/profile.d/bash_completion.sh" ]]; then
source "${pkgs.bash-completion}/etc/profile.d/bash_completion.sh"
fi
[ "''${BASH_COMPLETION_VERSINFO-}" ] || unset -v BASH_COMPLETION_VERSINFO
[ "$DISPLAY" ] && xset r rate 300 60
[ "$DISPLAY" ] && xset r rate 300 60
#-##################### user specific aliases and functions ######################
if [ -d ~/.bashrc.d ]; then
#-##################### user specific aliases and functions ######################
if [ -d ~/.bashrc.d ]; then
for rc in ~/.bashrc.d/*; do
bn=''${rc##*/}
if [ -f "''$rc" ] && [ -r "''$rc" ] && [ ! "''${bn::1}" = '.' ]; then
\. "''$rc"
fi
done
fi
unset rc bn
fi
unset rc bn
#-########################### shell settings & options ###########################
set -E
set -o pipefail
#-########################### shell settings & options ###########################
set -E
set -o pipefail
shopt -s nullglob dotglob globstar extglob
shopt -s autocd cdable_vars cdspell
shopt -s checkwinsize
shopt -s lastpipe
shopt -s inherit_errexit
shopt -s no_empty_cmd_completion
shopt -s histreedit
shopt -s lithist
shopt -u histverify
_have bash_abbr && shopt -u expand_aliases
shopt -s nullglob dotglob globstar extglob
shopt -s autocd cdable_vars cdspell
shopt -s checkwinsize
shopt -s lastpipe
shopt -s inherit_errexit
shopt -s no_empty_cmd_completion
shopt -s histreedit
shopt -s lithist
shopt -u histverify
_have bash_abbr && shopt -u expand_aliases
#-############################### shell variables ################################
FIGNORE='.o'
HISTCONTROL=ignoreboth:erasedups
HISTTIMEFORMAT='%y-%m-%d %H:%M:%S '
HISTSIZE=-1
HISTFILESIZE=-1
HISTFILE=''$HOME/.''${USER:-default}_bash_history
#-############################### shell variables ################################
FIGNORE='.o'
HISTCONTROL=ignoreboth:erasedups
HISTTIMEFORMAT='%y-%m-%d %H:%M:%S '
HISTSIZE=-1
HISTFILESIZE=-1
HISTFILE=''$HOME/.''${USER:-default}_bash_history
#-############################ environment variables #############################
export PYTHON_BASIC_REPL=1 # I'm good at readline so I'm gonna use readline whereever possible!
export LESS='-SRFX'
export PAGER='less' GIT_PAGER='less' MANPAGER='less' SYSTEMD_PAGER='less'
export BAT_PAGER='''
export EDITOR='vim' VISUAL='vim' FCEDIT='vim' SYSTEMD_EDITOR='vim'
export PATH
#-############################ environment variables #############################
export PYTHON_BASIC_REPL=1 # I'm good at readline so I'm gonna use readline whereever possible!
export LESS='-SRFX'
export PAGER='less' GIT_PAGER='less' MANPAGER='less' SYSTEMD_PAGER='less'
export BAT_PAGER='''
export EDITOR='vim' VISUAL='vim' FCEDIT='vim' SYSTEMD_EDITOR='vim'
export PATH
#-########################## generally useful functions ##########################
take () {
#-########################## generally useful functions ##########################
take () {
: 'Idempotently create directory recursively and cd into it'
local out
out=''$(set -o pipefail && mkdir -vp "''$@" | tail -1) || return
printf '%s\n' "''$out"
eval "out=''${out#"mkdir: created directory "}"
CDPATH= cd "''${out:-''${@: -1}}"
}
}
cd () {
cd () {
: 'Run cd; on success in a terminal, show the 4 newest entries (with a count of hidden ones)'
builtin cd "''$@" || return
@ -75,19 +71,19 @@ cd () {
mapfile -t lines < <(command ls --color=always --quoting-style=shell-escape -lArth)
if (( ''${#lines[@]} > 10 )); then
printf '\033[7m... %d more entries ...\033[27m\n' "$(( ''${#lines[@]} - 10 ))";
printf '%s\n' "''${lines[@]: -9}"
printf '%s\n' "''${lines[@]: -4}"
else
printf '%s\n' "''${lines[@]}"
fi
}
}
drop_caches () {
drop_caches () {
: 'Drop pagecache, dentries and inodes'
: 'https://unix.stackexchange.com/a/87909'
echo 3 | sudo tee /proc/sys/vm/drop_caches >/dev/null
}
}
respawn_shell () {
respawn_shell () {
: 'Intelligently respawn shell'
: 'pure posix sh without forking'
if [ "''${BASH_VERSINFO-}" ] && command -v bash 1>/dev/null 2>&1; then
@ -116,9 +112,9 @@ respawn_shell () {
printf 'You might want to manually run `exec [-l] "''$SHELL"`, however, `''$SHELL` might not be the shell you are currently running'
return 1
fi
}
}
export_bashrc () {
export_bashrc () {
CDPATH= command cd ~/.bashrc.d/ || return
: 'Not using an associative array because those are not sorted!'
declare -ar plugins=(*)
@ -225,10 +221,10 @@ export_bashrc () {
read -p 'Self destruct (y/N)? ' choice || :
[[ \''$choice = y ]] && { printf 'Trying to rm myself (%s)\\n' "\''${0@Q}"; rm -- "\''$0" && printf 'Success\\n' || printf 'Failed. Not trying further\\n'; }
EOF
}
}
#-#################################### binds #####################################
bind '"\e\C-r": kill-region' \
#-#################################### binds #####################################
bind '"\e\C-r": kill-region' \
'"\C-x\C-k": kill-whole-line' \
'"\e\C-p": history-search-backward' \
'"\e\C-n": history-search-forward' \
@ -246,23 +242,23 @@ bind '"\e\C-r": kill-region' \
'set colored-completion-prefix on' \
'set colored-stats on'
#-################################## autoclear ###################################
#-# TODO
#-################################## autoclear ###################################
#-# TODO
#-# prank () {
#-# line_up_until_cursor=''${READLINE_LINE::READLINE_POINT}
#-# line_after_cursor=''${READLINE_LINE:READLINE_POINT}
#-# if [[ ''$((RANDOM % 5)) -eq 0 ]]; then
#-# READLINE_LINE="''$line_up_until_cursor''$line_after_cursor"
#-# #READLINE_LINE="''$line_up_until_cursor''${1^}''$line_after_cursor"
#-# READLINE_POINT=''$((READLINE_POINT+1))
#-# else
#-# READLINE_LINE="''$line_up_until_cursor''$1''$line_after_cursor"
#-# READLINE_POINT=''$((READLINE_POINT+1))
#-# fi
#-# }
#-# bind -x '" ": prank " "'
#-# bind -x '"a": prank "a"'
#-# prank () {
#-# line_up_until_cursor=''${READLINE_LINE::READLINE_POINT}
#-# line_after_cursor=''${READLINE_LINE:READLINE_POINT}
#-# if [[ ''$((RANDOM % 5)) -eq 0 ]]; then
#-# READLINE_LINE="''$line_up_until_cursor''$line_after_cursor"
#-# #READLINE_LINE="''$line_up_until_cursor''${1^}''$line_after_cursor"
#-# READLINE_POINT=''$((READLINE_POINT+1))
#-# else
#-# READLINE_LINE="''$line_up_until_cursor''$1''$line_after_cursor"
#-# READLINE_POINT=''$((READLINE_POINT+1))
#-# fi
#-# }
#-# bind -x '" ": prank " "'
#-# bind -x '"a": prank "a"'
'';
};
}