Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ~/.bashrc:
- ----------
- ...
- for i in ~/.etc/bash/*; do
- source "$i"
- done
- ~/.etc/bash/bashaliasesrc:
- --------------------
- #======================================================================
- # This file contains aliases for interactive use. These are for use
- # with bindkey's vi-insert mode. See keybindingsrc for bindkey
- # vi-command mode commands.
- #======================================================================
- alias src='source ~/.bashrc'
- alias vi='TERM=xterm-256color-it gvim -v'
- alias vim='TERM=xterm-256color-it gvim -v'
- alias pdf='okular'
- alias cls='cd;reset'
- alias conf='$EDITOR ~/.bashrc ~/.etc/bash/*'
- alias doc='cd ~/Documents'
- alias x='exit'
- if [[ $TERM != dumb ]]; then
- alias ls='ls --color=auto --group-directories-first'
- else
- alias ls='ls --group-directories-first'
- fi
- alias info='pinfo'
- alias tmux='TERM=screen-256color tmux'
- alias t='todo.sh -t -n -a'
- alias tedit='vim ~/Documents/t/todo/{todo,done}.txt'
- alias learnperl='cd ~/projects/perl/learning-perl; ./pldev'
- alias -- -='cd -'
- ~/.etc/bash/keybindingsrc:
- --------------------------
- #======================================================================
- # This has key bindings for vi-command mode for the most part.
- #======================================================================
- # set bash for vi keybindings
- set -o vi
- # clear the screen
- # bind -m vi-insert '"\C-l":clear-screen'
- bind -m vi-command '",l":clear-screen'
- # set up z to quit bash
- bind -m vi-command -x '"z":exit'
- # display help for vi-mode
- bind -m vi-command -x '",h":pg /home/scott/Documents/b/bash-vi-editing-mode-cheat-sheet.2014-11-01.txt'
- # bind -m vi-insert -x '"\C-h":pg /home/scott/Documents/b/bash-vi-editing-mode-cheat-sheet.2014-11-01.txt'
- # display help for konsole
- bind -m vi-command -x '",k":pg /home/scott/Documents/n/notes/konsole-shortcuts.2014-05-04.v001.txt'
- #bind -m vi-insert -x '"\c-k":pg /home/scott/Documents/n/notes/konsole-shortcuts.2014-05-04.v001.txt'
- # source .bashrc
- bind -m vi-command -x '",s":src'
- # edit bash configuration
- bind -m vi-command -x '",v":$EDITOR ~/.bashrc ~/.etc/bash/*'
- # start file manager
- bind -m vi-command -x '",f":krusader 2>/dev/null'
- ~/.etc/bash/functionsrc:
- ------------------------
- #======================================================================
- # This file contains shell functions that are more complex than simple
- # aliases. These are for interactive use.
- #======================================================================
- #======================================================================
- # make a list of files in subdirectories in a pager. Optionally use
- # find to locate specific files in all subdirectories.
- #======================================================================
- function lst () {
- if [[ $# -eq 0 ]]; then
- ls ./* | $PAGER
- else
- local files=( $(find . -name "*${*}*" -type f 2>/dev/null | sort) )
- local promptLines=$(echo -e "$PS1" | wc -l)
- if [[ ${#files[@]} -ge $(( LINES - promptLines )) ]]; then
- for f in "${files[@]}"; do
- echo $f
- done | $PAGER
- else
- for f in "${files[@]}"; do
- echo $f
- done
- fi
- unset f
- fi
- } 2>/dev/null
- #======================================================================
- # Display a hex dump of a file in the default pager
- #======================================================================
- function hex () {
- if [[ $# -gt 1 ]]; then
- printf '%q: too many parameters\n' hex >&2
- return 1
- fi
- if [[ $# -eq 0 ]]; then
- printf '%q: file name required\n' hex >&2
- return 1
- fi
- if ! [[ -f $1 ]]; then
- printf '%q: file not found: %q\n' hex "$1" >&2
- return 1
- fi
- hexdump -C "$1" | $PAGER
- }
- #======================================================================
- # sizeof - show byte size of one or more files
- #======================================================================
- function sizeof () {
- if [[ $# -eq 1 ]]; then
- stat -c %s "$1"
- else
- for f in "$@"; do
- [[ -f $f ]] && printf '%8d: %s\n' "$(stat -c %s "$f")" "$f"
- done
- fi
- }
- #======================================================================
- # Format a file (or standard input) and display it or page it if
- # necessary
- # pg [-n] [file]
- # -n add line numbers to output
- #======================================================================
- pg () {
- local ncols=0 # columns used for line numbering
- local -r promptLines=$(echo -e "$PS1" | wc -l) # number of lines taken by PS1 prompt
- # capture standard input
- # huge files can, of course, fill all available memory
- while IFS='' read -r -t 0.1 line; do
- if ! [[ -v pipeFile ]]; then
- if [[ "$1" = '-n' ]]; then
- ncols=8
- fi
- local -a pipeFile # array of lines from piped file
- local inc # amount to increment lineCount each pass through loop
- local lineCount # total number of formatted lines of output
- fi
- # add current text line to list of lines, determine how many formatted lines
- # will result from it, and increment the total number of lines by that many
- pipeFile=( "${pipeFile[@]}" "$line" )
- inc=$(fmt -s -w $(( COLUMNS - ncols )) <<< $line | wc -l)
- lineCount=$(( lineCount + inc ))
- done
- # set up line numbering
- if [[ "$1" = '-n' ]]; then
- ncols=8
- local -A num
- num[cat]='-n' # parameter for turning on line numbering in cat
- num[less]='-N' # parameter for turning on line numbering in less
- shift
- fi
- # if taking input from a file
- if [[ $# -gt 0 ]]; then # is there a file names to process?
- if [[ -f "$1" ]]; then # and is it a regular file?
- # format file and feed it to either less or cat
- fmt -s -w $(( COLUMNS - ncols )) "$1" |
- if [[ $(fmt -s -w $(( COLUMNS - ncols )) "$1" | wc -l) \
- -gt $(( LINES - promptLines )) ]]; then
- command less -R ${num[less]}
- else
- command cat ${num[cat]}
- fi
- elif [[ -d "$1" ]]; then
- printf '%s: %s: Is a directory\n' 'pg' "$1" >&2
- else
- printf '%s: %s: No such file or directory\n' 'pg' "$1" >&2
- fi
- elif [[ -v pipeFile ]]; then # taking input from standard input
- for line in "${pipeFile[@]}"; do
- echo "$line"
- done |
- fmt -s -w $(( COLUMNS - ncols )) |
- if [[ lineCount -gt $(( LINES - promptLines )) ]]; then
- command less -R ${num[less]}
- elif [[ lineCount -gt 0 ]]; then
- command cat ${num[cat]}
- else
- :
- fi
- fi
- }
- #======================================================================
- # Customize how which operates
- #======================================================================
- function which () {
- { alias; declare -f; } | /usr/bin/which --tty-only --read-alias \
- --read-functions --show-tilde --show-dot "$@"
- }
- export -f which
- #======================================================================
- # Run perl interactively
- #======================================================================
- iperl () {
- clear
- command perl -de 42
- clear
- }
- up() {
- #======================================================================
- # move up the directory tree
- # usage: up [N]
- # N is an integer (defaults to 1)
- #
- # silently exits if non-numeric input given
- # translates signed integers to absolute values
- # ignores all but the first parameter
- #
- # exit codes:
- # 0: success
- # 1: invalid input
- # 2: unable to change directory
- # 255: nothing to do
- #======================================================================
- # ensure PWD points to the real working directory
- # side-effect resets global PWD to working directory
- if ! command cd -P . && [[ $PWD != $(command realpath .) ]]; then
- printf '$PWD spoofed to: %s\nReal working directory is: %s\n' \
- "$PWD" "$(command realpath .)" >&2
- local PWD=$(command realpath .)
- fi
- # convert parameter to an absolute value, if possible, or return error code
- local levels="${1:-1}" # set the number of levels up the directory tree to traverse
- levels=${levels#*-} # strip leading negative sign
- levels=${levels#*+} # strip leading positive sign
- if [[ $levels =~ [^[:digit:]] ]]; then
- return 1
- fi
- local targetDir="$PWD" # new working directory starts from the current directory
- # set targetDir to target directory
- local l
- for (( l=1; l<=levels; l++ )); do
- # %/* will produce an empty string in first-level directories. This handles that case
- if [[ -n "${targetDir%/*}" ]]; then
- targetDir="${targetDir%/*}"
- else # set targetDir to / and break out of loop
- targetDir=/
- break
- fi
- done
- # if new working directory is different from current directory, change directories
- if [[ "$targetDir" != "$PWD" ]]; then
- command cd -P "$targetDir" || return 2 # if cd fails
- else
- return -1 # nothing to do (exit code = 255)
- fi
- }
- #======================================================================
- # customizes the PS1 prompt
- #======================================================================
- ps1 () {
- export ps1
- # is $PWD somewhere within $HOME?
- if [[ $PWD =~ ^$HOME ]]; then
- # is this $HOME?
- if [[ "$PWD" = "$HOME" ]]; then
- :
- # is $PWD top-level within $HOME?
- elif [[ "$HOME/${PWD##*/}" = "$PWD" ]]; then
- printf '\[\e[0;34m\]/\[\e[1;31m\]%s' "${PWD##*/}"
- # must be a lower-level directory within $HOME
- else
- local p=${PWD#*$USER/}
- local dots=''
- # substitute single dots for each subdirectory level below $HOME
- while grep / <<< "$p" >/dev/null; do
- p=${p#*/}
- dots="${dots}."
- done
- printf '\[\e[0;34m\]/\[\e[1;31m\]%s\[\e[0;34m\]/\[\e[1;31m\]%s' "$dots" "${PWD##*/}"
- fi
- # $PWD is somewhere other than $HOME
- else
- printf '\[\e[0;34m\]/(\[\e[1;31m\]%s\[\e[0;34m\])' "$PWD"
- fi
- # is this a regular user?
- if [[ $UID -gt 0 ]]; then
- printf '\[\e[0;30m\] \$\[\e[1;30m\] '
- # must be root
- else
- printf '\[\e[0;31m\] \$\[\e[1;30m\] '
- fi
- }
- #======================================================================
- # list 10 most-used commands
- #======================================================================
- mostused () {
- history |\
- awk '{CMD[$2]++;count++;}END { for (a in CMD)print CMD[a] " " CMD[a]/count*100 "% " a;}' |\
- grep -v "./" |\
- column -c3 -s " " -t |\
- sort -nr |\
- nl |\
- head -n10
- }
- ~/.etc/bash/environmentrc:
- ---------------------
- #======================================================================
- # This file contains environment variables that apply to all programs
- # and to the shell itself. Program-specific environment variables
- # should be in program-specific files, instead.
- #======================================================================
- export PAGER='/usr/bin/less'
- export LESS='-R'
- export VIEWER="$PAGER"
- export MAILER='/usr/bin/kmail'
- export BROWSER='/usr/bin/firefox'
- export EDITOR='/usr/bin/vim'
- export VISUAL='/usr/bin/vim'
- export FCEDIT='/usr/bin/vim'
- export HISTSIZE='1000'
- export HISTIGNORE='cd:ls:[bf]g:clear:exit'
- export HISTCONTROL='ignoreboth:erasedups'
- export PROMPT_COMMAND='history -a; history -n; history -w; export PS1="\n\[\e[0;36m\]\H\[\e[0;34m\]/\[\e[1;31m\]~\[\e[0;36m\]\u$(ps1)"'
- export CDPATH='.:~:~/Documents:~/Videos:~/Music:~/Downloads:~/Pictures:~/Desktop:~/Mail:~/Dropbox'
- export LINES
- export COLUMNS
- export COLORTERM=$TERM
- export MAN_POSIXLY_CORRECT=1
- ~/.etc/bash/bashoptionsrc:
- --------------------------
- #======================================================================
- # This file contains shell options for interactive use.
- #======================================================================
- shopt -s autocd
- shopt -s cdable_vars
- shopt -s cdspell
- shopt -s dirspell
- shopt -s checkhash
- shopt -s globstar
- shopt -s histappend
- shopt -s checkwinsize
Advertisement
Add Comment
Please, Sign In to add comment