- && [[ $- == *c* ]] \
- && [[ ! $SSH_TTY ]] \
- && [[ ! $BASH_LOGIN_SHELL == true ]] \
- && [[ $- != *i* ]]; then
- return
-fi
-
-# Side note on ssh.
-
-
-
-###################
-## include files ###
-###################
-
-for x in $HOME/bin/bash-programs-by-ian/repos/*/*-function; do
- source "$x"
-done
-
-source $HOME/bin/semi-private # so I can share my bashrc
-source $HOME/path_add-function
-
-
-
-
-############
-# settings #
-############
-
-CDPATH=.:/a
-
-# remove gnome keyring warning messages
-# there is probably a more proper way, but I didn't find any easily on google
-unset GNOME_KEYRING_CONTROL
-
-#use extra globing features. See man bash, search extglob.
-shopt -s extglob
-#include .files when globbing.
-shopt -s dotglob
-#but ignore files name . and ..
-#those are default when this is set to anything, so we just set it to one of them
-export GLOBIGNORE=.
-
-# broken with bash_completion package. Saw a bug for this once. Don't anymore.
-# still broken in wheezy
-# still buggered in latest stable from the web, version 2.1
-# perhaps its fixed in newer git version, which fails to make for me
-#shopt -s nullglob
-
-# make tab on an empty line do nothing
-shopt -s no_empty_cmd_completion
-
-# advanced completion
-# http://bash-completion.alioth.debian.org/
-# might be sourced by the system already, but I've noticed it not being sourced before
-if ! type _init_completion &> /dev/null && [[ -r "/usr/share/bash-completion/bash_completion" ]]; then
- . /usr/share/bash-completion/bash_completion
-fi
-
-
-# fix spelling errors for cd, only in interactive shell
-shopt -s cdspell
-# append history instead of overwritting it
-shopt -s histappend
-# for compatibility, per gentoo/debian bashrc
-shopt -s checkwinsize
-# attempt to save multiline single commands as single history entries.
-shopt -s cmdhist
-
-
-# inside emacs fixes
-if [[ $INSIDE_EMACS ]]; then
- export INSIDE_EMACS
- export PAGER=cat
- export MANPAGER=cat
- # for readline-complete.el
- stty echo
-fi
-
-
-if [[ $- == *i* ]]; then
- # for readline-complete.el
- if [[ $INSIDE_EMACS ]]; then
- bind 'set horizontal-scroll-mode on'
- bind 'set print-completions-horizontally on'
- else
- # arrow keys. for other terminals, see http://unix.stackexchange.com/questions/10806/how-to-change-previous-next-word-shortcut-in-bash
- if [[ $TERM == "xterm" ]]; then
- bind '"\e[1;5C": shell-forward-word' 2>/dev/null
- bind '"\e[1;5D": shell-backward-word' 2>/dev/null
- else
- bind '"\eOc": shell-forward-word'
- bind '"\eOd": shell-backward-word'
- fi
- # terminal keys: C-c, C-z. the rest defined by stty -a are, at least in
- # gnome-terminal, overridden by bash, or disabled by the system
- stty werase undef lnext undef stop undef start undef
-
- fi
-
-fi
-
-
-# history number. History expansion is good.
-PS4='$LINENO+ '
-# history file size limit, set to unlimited.
-# this needs to be different from the default because
-# default HISTFILESIZE is 500 and could clobber our history
-HISTFILESIZE=
-# max commands 1 session can append/read from history
-HISTSIZE=100000
-# my own history size limit based on lines
-HISTFILELINES=1000000
-HISTFILE=$HOME/.bh
-# the time format display when doing the history command
-# also, setting this makes the history file record time
-# of each command as seconds from the epoch
-HISTTIMEFORMAT="%I:%M %p %m/%d "
-# consecutive duplicate lines don't go in history
-HISTCONTROL=ignoredups
-# just defensively unsetting this
-# this var can replace HISTCONTROL to do more flexible things like
-# not saving single char history items or specific names
-unset HISTIGNORE
-
-export BC_LINE_LENGTH=0
-
-path_add --ifexists /a/opt/adt-bundle*/tools /a/opt/adt-bundle*/platform-tools
-path_add $HOME/bin/bash-programs-by-ian/utils
-# note, if I use a machine I don't want files readable by all users, set
-# umask 077 # If fewer than 4 digits are entered, leading zeros are assumed
-
-C_DEFAULT_DIR=/a
-
-
-
-
-###############
-### aliases ###
-###############
-
-if [[ $- == *i* ]]; then
- alias cp='cp -i'
- alias mv='mv -i'
-fi
-
-# remove any default aliases for these
-alias ls > /dev/null 2>&1 && unalias ls
-alias ll > /dev/null 2>&1 && unalias ll
-alias grep > /dev/null 2>&1 && unalias grep
-
-
-mkdir() {
- command mkdir -p "$@"
-}
-
-
-alias d='builtin bg'
-complete -A stopped -P '"%' -S '"' d
-
-alias hi='history'
-
-
-# note: gksudo is recommended for X apps because it does not set the
-# home directory to the same.
-
-if [[ $- == *i* ]]; then
- # extra space at the end allows aliases to work
- alias s='SUDOD="$PWD" sudo -i '
-else
- s() {
- if [[ $EUID != 0 || $1 == -* ]]; then
- local SUDOD="$PWD"
- sudo -i "$@"
- else
- "$@"
- fi
- }
-fi
-
-
-
-if [[ $OS == Windows_NT ]]; then
- alias ffs='cygstart "/c/Program Files (x86)/Mozilla Firefox/firefox.exe" -P scratch'
- export DISPLAY=nt
- alias j='command cygpath'
- alias t='command cygstart'
- alias cygstart='echo be quick, use the alias "t" instead :\)'
- alias cygpath='echo be quick, use the alias "j" instead :\)'
-
-fi
-
-
-#####################
-### functions ####
-#####################
-
-
-
-a() {
- beet "${@}"
-}
-
-
-t() {
- trash-put "$@"
-}
-
-
-if type ack-grep >/dev/null 2>&1; then
- alias ack=ack-grep
-fi
-
-
-gr() {
- grep -i --binary-files=without-match --color=auto "$@"
-}
-
-grr() {
- grep -ri --binary-files=without-match --color=auto "$@"
-}
-
-
-
-
-calc() { echo "scale=3; $*" | bc -l; }
-
-
-# makes it so chown -R symlink affects the symlink and its target.
-chown() {
- if [[ $1 == -R ]]; then
- shift
- command chown -h "$@"
- command chown "$@"
- command chown -RH "$@"
- else
- command chown "$@"
- fi
-}
-
-
-
-cgpl ()
-{
- if [[ $# == 0 ]]; then
- cp /a/bin/data/COPYING .
- else
- cp /a/bin/data/COPYING "$@"
- fi
-}
-
-
-dc() {
- diff --strip-trailing-cr -w "$@" # diff content
-}
-
-
-distro_name() {
- if [[ -f /etc/fedora-release ]]; then
- echo fedora
- else
- grep "^ID=.*" /etc/os-release | sed 's/^ID=//'
- fi
-}
-
-
-dt() {
- date "+%A, %B %d, %r" "$@"
-}
-
-
-e() { echo "$@"; }
-
-
-envload() { # load environment from a previous: export > file
- local file=${1:-$HOME/.${USER}_env}
- eval "$(export | sed 's/^declare -x/export -n/')"
- while IFS= read -r line; do
- # declare -x makes variables local to a function
- eval ${line/#declare -x/export}
- done < "$file"
-}
-
-
-
-# havn't tested these:
-#file cut copy and paste, like the text buffers :)
-_fbufferinit() { # internal use by
- ! [[ $my_f_tempdir ]] && my_f_tempdir=$(mktemp -d)
- rm -rf "$my_f_tempdir"/*
-}
-fcp() { # file cp
- _fbufferinit
- cp "$@" "$my_f_tempdir"/
-}
-fct() { # file cut
- _fbufferinit
- mv "$@" "$my_f_tempdir"/
-}
-fpst() { # file paste
- [[ $2 ]] && { echo too many arguments; return 1; }
- target=${1:-.}
- cp "$my_f_tempdir"/* "$target"
-}
-
-
-# find array. make an array of file names found by find into $x
-# argument: find arguments
-# return: find results in an array $x
-fa() {
- while read -rd ''; do
- x+=("$REPLY");
- done < <(find "$@" -print0);
-}
-
-
-git_empty_branch() { # start an empty git branch. carefull, it deletes untracked files.
- [[ $# == 1 ]] || { echo 'need a branch name!'; return 1;}
- local gitroot
- gitroot || return 1 # function to set gitroot
- builtin cd $gitroot
- git symbolic-ref HEAD refs/heads/$1
- rm .git/index
- git clean -fdx
-}
-
-fw() {
- firefox -P default "$@" >/dev/null 2>&1
-}
-
-fn() {
- firefox -P alt "$@" >/dev/null 2>&1
-}
-
-
-
-
-
-# horizontal row. used to break up output
-hr() { printf "$(tput setaf 5)█$(tput sgr0)%.0s" $(seq $COLUMNS); }
-
-
-i() {
- git "$@"
-}
-# modified from ~/local/bin/git-completion.bash
-# other completion commands are mostly taken from bash_completion package
-complete -o bashdefault -o default -o nospace -F _git i 2>/dev/null \
- || complete -o default -o nospace -F _git i
-
-
-# insensitive find
-ifn () {
- find . -iname '*'"$*"'*'
-}
-
-
-
-l() {
- if [[ $PWD == /[iap] ]]; then
- command ls -A --color=auto -I lost+found "$@"
- else
- command ls -A --color=auto "$@"
- fi
-}
-
-
-lld() { ll -d "$@"; }
-
-
-low() { # make filenames all lowercase
- local x y
- for x in "$@"; do
- y=$(tr "[A-Z]" "[a-z]" <<<"$x")
- [[ $y != $x ]] && mv "$x" "$y"
- done
-}
-
-
-lower() { # make first letter of filenames lowercase.
- local x
- for x in "$@"; do
- if [[ ${x::1} == [A-Z] ]]; then
- y=$(tr "[A-Z]" "[a-z]" <<<"${x::1}")"${x:1}"
- safe_rename "$x" "$y"
- fi
- done
-}
-
-safe_rename() {
- if [[ $# != 2 ]]; then
- echo safe_rename error: $# args, need 2 >2
- return 1
- elif [[ $1 != $2 ]]; then
- if [[ -e $2 ]]; then
- echo Cannot rename "$1" to "$2" as it already exists.
- else
- mv "$1" "$2"
- fi
- fi
-}
-
-despace() {
- local x y
- for x in "$@"; do
- y="${x// /_}"
- safe_rename "$x" "$y"
- done
-}
-
-# force symbolic link creation.
-# trash-put any existing files where links would be created.
-# mkdir -p the directory containing the link(s) if needed.
-# then do ln -s -- "$@"
-lnf() {
- if [[ $# -gt 2 && ! -d ${!#} ]]; then
- mkdir -p "${!#}"
- fi
- if [[ $# -gt 1 && -d ${!#} ]]; then
- local oldcwd=$PWD
- cd ${!#} # last arg
- for x in "${@:1:$(($#-1))}"; do # all but last arg
- # remove any trailing slashes
- x="${x%%+(/)}"
- # remove any leading directory components
- x="${x##*/}"
- te "$x" && trash-put "$x"
- done
- cd "$oldcwd"
- elif [[ $# -eq 2 ]]; then
- if te "$2"; then
- trash-put "$2"
- elif [[ ! -d $(getdir "$2") ]]; then
- mkdir -p $(getdir "$2")
- fi
- else
- te "${1##*/}" && rm "${1##*/}"
- fi
- ln -s -- "$@"
-}
-
-
-
-# package manager
-# aliases would be much more compact, but they can't be used as ssh commands
-# also, to be used in a script, you need -i which prints annoying
-# warnings. instead, use -l in a script to source this file
-if type -p yum > /dev/null; then
- p() {
- if [[ $EUID == 0 ]]; then
- yum "$@"
- else
- sudo yum "$@"
- fi
- }
- pi() {
- if [[ $EUID == 0 ]]; then
- yum -y install "$@"
- else
- sudo yum -y install "$@"
- fi
- }
- pf() {
- if [[ $EUID == 0 ]]; then
- yum search "$@"
- else
- sudo yum search "$@"
- fi
- }