addet sane bash
This commit is contained in:
parent
b2881f0dca
commit
82ce3a6230
1 changed files with 129 additions and 38 deletions
167
.bashrc
167
.bashrc
|
@ -14,26 +14,119 @@ function echo_info() { echo -e "\033[0;35m${*}\033[0m"; }
|
|||
# *) return ;;
|
||||
# esac
|
||||
|
||||
_sensible.bash_(){
|
||||
# Sensible Bash - An attempt at saner Bash defaults
|
||||
# Maintainer: mrzool <http://mrzool.cc>
|
||||
# Repository: https://github.com/mrzool/bash-sensible
|
||||
# Version: 0.2.2
|
||||
|
||||
# Unique Bash version check
|
||||
if ((BASH_VERSINFO[0] < 4))
|
||||
then
|
||||
echo "sensible.bash: Looks like you're running an older version of Bash."
|
||||
echo "sensible.bash: You need at least bash-4.0 or some options will not work correctly."
|
||||
echo "sensible.bash: Keep your software up-to-date!"
|
||||
fi
|
||||
|
||||
## GENERAL OPTIONS ##
|
||||
|
||||
# Prevent file overwrite on stdout redirection
|
||||
# Use `>|` to force redirection to an existing file
|
||||
set -o noclobber
|
||||
|
||||
# Update window size after every command
|
||||
shopt -s checkwinsize
|
||||
|
||||
# Automatically trim long paths in the prompt (requires Bash 4.x)
|
||||
PROMPT_DIRTRIM=2
|
||||
|
||||
# Enable history expansion with space
|
||||
# E.g. typing !!<space> will replace the !! with your last command
|
||||
bind Space:magic-space
|
||||
|
||||
# Turn on recursive globbing (enables ** to recurse all directories)
|
||||
shopt -s globstar 2> /dev/null
|
||||
|
||||
# Case-insensitive globbing (used in pathname expansion)
|
||||
shopt -s nocaseglob;
|
||||
|
||||
## SMARTER TAB-COMPLETION (Readline bindings) ##
|
||||
|
||||
# Perform file completion in a case insensitive fashion
|
||||
bind "set completion-ignore-case on"
|
||||
|
||||
# Treat hyphens and underscores as equivalent
|
||||
bind "set completion-map-case on"
|
||||
|
||||
# Display matches for ambiguous patterns at first tab press
|
||||
bind "set show-all-if-ambiguous on"
|
||||
|
||||
# Immediately add a trailing slash when autocompleting symlinks to directories
|
||||
bind "set mark-symlinked-directories on"
|
||||
|
||||
## SANE HISTORY DEFAULTS ##
|
||||
|
||||
# Append to the history file, don't overwrite it
|
||||
shopt -s histappend
|
||||
|
||||
# Save multi-line commands as one command
|
||||
shopt -s cmdhist
|
||||
|
||||
# Record each line as it gets issued
|
||||
PROMPT_COMMAND='history -a'
|
||||
|
||||
# Huge history. Doesn't appear to slow things down, so why not?
|
||||
HISTSIZE=500000
|
||||
HISTFILESIZE=100000
|
||||
|
||||
# Avoid duplicate entries
|
||||
HISTCONTROL="erasedups:ignoreboth"
|
||||
|
||||
# Don't record some commands
|
||||
export HISTIGNORE="&:[ ]*:exit:ls:bg:fg:history:clear"
|
||||
|
||||
# Use standard ISO 8601 timestamp
|
||||
# %F equivalent to %Y-%m-%d
|
||||
# %T equivalent to %H:%M:%S (24-hours format)
|
||||
HISTTIMEFORMAT='%F %T '
|
||||
|
||||
# Enable incremental history search with up/down arrows (also Readline goodness)
|
||||
# Learn more about this here: http://codeinthehole.com/writing/the-most-important-command-line-tip-incremental-history-searching-with-inputrc/
|
||||
bind '"\e[A": history-search-backward'
|
||||
bind '"\e[B": history-search-forward'
|
||||
bind '"\e[C": forward-char'
|
||||
bind '"\e[D": backward-char'
|
||||
|
||||
## BETTER DIRECTORY NAVIGATION ##
|
||||
|
||||
# Prepend cd to directory names automatically
|
||||
shopt -s autocd 2> /dev/null
|
||||
# Correct spelling errors during tab-completion
|
||||
shopt -s dirspell 2> /dev/null
|
||||
# Correct spelling errors in arguments supplied to cd
|
||||
shopt -s cdspell 2> /dev/null
|
||||
|
||||
# This defines where cd looks for targets
|
||||
# Add the directories you want to have fast access to, separated by colon
|
||||
# Ex: CDPATH=".:~:~/projects" will look for targets in the current working directory, in home and in the ~/projects folder
|
||||
CDPATH="."
|
||||
|
||||
# This allows you to bookmark your favorite places across the file system
|
||||
# Define a variable containing a path and you will be able to cd into it regardless of the directory you're in
|
||||
shopt -s cdable_vars
|
||||
|
||||
# Examples:
|
||||
# export dotfiles="$HOME/dotfiles"
|
||||
# export projects="$HOME/projects"
|
||||
# export documents="$HOME/Documents"
|
||||
# export dropbox="$HOME/Dropbox"
|
||||
}
|
||||
|
||||
_defaults_() {
|
||||
# ─< set keybinding mode >────────────────────────────────────────────────────────────────
|
||||
set -o emacs
|
||||
# set -o vim
|
||||
|
||||
# don't put duplicate lines or lines starting with space in the history.
|
||||
# See bash(1) for more options
|
||||
HISTCONTROL=ignoreboth
|
||||
|
||||
# append to the history file, don't overwrite it
|
||||
shopt -s histappend
|
||||
|
||||
# for setting history length see HISTSIZE and HISTFILESIZE in bash(1)
|
||||
HISTSIZE=1000
|
||||
HISTFILESIZE=2000
|
||||
|
||||
# check the window size after each command and, if necessary,
|
||||
# update the values of LINES and COLUMNS.
|
||||
shopt -s checkwinsize
|
||||
|
||||
# If set, the pattern "**" used in a pathname expansion context will
|
||||
# match all files and zero or more directories and subdirectories.
|
||||
#shopt -s globstar
|
||||
|
@ -45,6 +138,27 @@ _defaults_() {
|
|||
if [ -z "${debian_chroot:-}" ] && [ -r /etc/debian_chroot ]; then
|
||||
debian_chroot=$(cat /etc/debian_chroot)
|
||||
fi
|
||||
# If this is an xterm set the title to user@host:dir
|
||||
case "$TERM" in
|
||||
xterm* | rxvt*)
|
||||
PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1"
|
||||
;;
|
||||
*) ;;
|
||||
esac
|
||||
|
||||
# Add an "alert" alias for long running commands. Use like so:
|
||||
# sleep 10; alert
|
||||
alias alert='notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "$(history|tail -n1|sed -e '\''s/^\s*[0-9]\+\s*//;s/[;&|]\s*alert$//'\'')"'
|
||||
|
||||
# Alias definitions.
|
||||
# You may want to put all your additions into a separate file like
|
||||
# ~/.bash_aliases, instead of adding them here directly.
|
||||
# See /usr/share/doc/bash-doc/examples in the bash-doc package.
|
||||
|
||||
if [ -f ~/.bash_aliases ]; then
|
||||
. ~/.bash_aliases
|
||||
fi
|
||||
}
|
||||
|
||||
_color_prompt_() {
|
||||
# set a fancy prompt (non-color, unless we know we "want" color)
|
||||
|
@ -75,29 +189,6 @@ _defaults_() {
|
|||
fi
|
||||
unset color_prompt force_color_prompt
|
||||
}
|
||||
|
||||
# If this is an xterm set the title to user@host:dir
|
||||
case "$TERM" in
|
||||
xterm* | rxvt*)
|
||||
PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1"
|
||||
;;
|
||||
*) ;;
|
||||
esac
|
||||
|
||||
# Add an "alert" alias for long running commands. Use like so:
|
||||
# sleep 10; alert
|
||||
alias alert='notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "$(history|tail -n1|sed -e '\''s/^\s*[0-9]\+\s*//;s/[;&|]\s*alert$//'\'')"'
|
||||
|
||||
# Alias definitions.
|
||||
# You may want to put all your additions into a separate file like
|
||||
# ~/.bash_aliases, instead of adding them here directly.
|
||||
# See /usr/share/doc/bash-doc/examples in the bash-doc package.
|
||||
|
||||
if [ -f ~/.bash_aliases ]; then
|
||||
. ~/.bash_aliases
|
||||
fi
|
||||
}
|
||||
|
||||
# ─< check if command exists >────────────────────────────────────────────────────────────
|
||||
command_exists() {
|
||||
command -v "$1" >/dev/null 2>&1
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue