Fix cd function and dedent everything so it's nice and clean
This commit is contained in:
parent
e64ef32112
commit
10c415c3e5
1 changed files with 235 additions and 235 deletions
|
|
@ -10,61 +10,61 @@ if [[ ! -v BASH_COMPLETION_VERSINFO ]] &&
|
|||
source "${pkgs.bash-completion}/etc/profile.d/bash_completion.sh"
|
||||
fi
|
||||
|
||||
[ "$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 +75,19 @@ fi
|
|||
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[@]: -4}"
|
||||
printf '%s\n' "''${lines[@]: -9}"
|
||||
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 +116,9 @@ fi
|
|||
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 +225,10 @@ fi
|
|||
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 +246,23 @@ fi
|
|||
'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"'
|
||||
'';
|
||||
};
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue