You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

146 lines
4.6 KiB
Bash

5 years ago
#!/usr/bin/env bash
# shellcheck disable=SC1091
5 years ago
# vim:ts=4:sts=4:sw=4:et
#
# Author: Hari Sekhon
# Date: 2006-06-28 23:25:09 +0100 (Wed, 28 Jun 2006)
#
# https://github.com/harisekhon/bash-tools
#
# License: see accompanying Hari Sekhon LICENSE file
#
# If you're using my code you're welcome to connect with me on LinkedIn and optionally send me feedback to help steer this or other code I publish
#
# https://www.linkedin.com/in/harisekhon
#
# ============================================================================ #
# BASH - Heavily Customized Environment
# ============================================================================ #
5 years ago
# Sources thousands of lines of Bash code written over the course of ~15+ years
# some of which is now found in this GitHub repo's .bash.d/*.sh
5 years ago
5 years ago
# ============================================================================ #
#
# put this at the top of your ~/.bashrc to inherit the goodness here (assuming you've checked out this repo to ~/github/bash-tools):
#
# if [ -f ~/github/bash-tools/.bashrc ]; then
# . ~/github/bash-tools/.bashrc
# fi
#
# ============================================================================ #
5 years ago
5 years ago
# Use with PS4 further down + profile-bash.pl (still in private repos) for performance profiling this bashrc
5 years ago
#set -x
# If not running interactively, don't do anything:
[ -z "${PS1:-}" ] && return
[ -n "${PERLBREW_PERL:-}" ] && return
# Another alternative
#case $- in
# *i*) ;;
# *) return 0;;
#esac
# Another variation
#if [[ $- != *i* ]] ; then
# # Shell is non-interactive. Be done now!
# return
#fi
5 years ago
bash_tools="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
5 years ago
5 years ago
# shellcheck disable=SC1090
5 years ago
. "$bash_tools/.bash.d/os_detection.sh"
5 years ago
# enable color support for ls
5 years ago
if [ "$TERM" != "dumb" ] && \
[ -z "${APPLE:-}" ]; then
eval "$(dircolors -b)"
5 years ago
fi
[ -f /etc/profile ] && . /etc/profile
[ -f /etc/bash/bashrc ] && . /etc/bash/bashrc
[ -f /etc/bashrc ] && . /etc/bashrc
# SECURITY TO STOP STUFF BEING WRITTEN TO DISK
#unset HISTFILE
#unset HISTFILESIZE
export HISTSIZE=50000
export HISTFILESIZE=50000
5 years ago
rmhist(){ history -d "$1"; }
histrm(){ rmhist "$1"; }
5 years ago
histrmlast(){ history -d "$(history | tail -n 2 | head -n 1 | awk '{print $1}')"; }
# This adds a time format of "YYYY-mm-dd hh:mm:ss command" to the bash history
export HISTTIMEFORMAT="%F %T "
# Stops duplicate commands next to each other from being logged
# This totally screws up my terminal to the point where I can't even ssh, I get a strange network tcp network destination unreachable error
#export HISTCONTROL=ignoredups
HISTCONTROL=ignoredups:ignorespace
# Neat trick "[ \t]*" to exclude any command by just prefixing it with a space. Fast way of going stealth for pw entering on cli
# & here means any duplicate patterns, others are simple things like built-ins and ls and stuff you don't need history for
#export HISTIGNORE="[ \t]*:&:ls:[bf]g:exit"
# Make sure we append rather than overwrite history
shopt -s histappend
# check the window size after each command and, if necessary,
# update the values of LINES and COLUMNS.
shopt -s checkwinsize
[ -n "${APPLE:-}" ] || setterm -blank 0
# Prevent core dumps which can leak sensitive information
ulimit -c 0
# Let's be stingey with permissions
# This causes problems where root installs libraries and my user account can't access them
if [ $EUID = 0 ]; then
umask 0022
else
# This causes no end of problems when doing sudo command which retains 0077 and breaks library access. If can get sudo to implicitly read .bashrc to reset this (and prompt colour would be nice) then re-enable this tighter 0077 umask
#umask 0077
umask 0022
fi
# make less more friendly for non-text input files, see lesspipe(1)
[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)"
# ============================================================================ #
5 years ago
sudo=sudo
if [ $EUID -eq 0 ]; then
5 years ago
# used throughout .bash.d/*.sh
# shellcheck disable=SC2034
5 years ago
sudo=""
fi
5 years ago
type add_PATH &>/dev/null || . "$bash_tools/.bash.d/paths.sh"
5 years ago
# ============================================================================ #
5 years ago
for src in "$bash_tools/.bash.d/"*.sh; do
5 years ago
# shellcheck disable=SC1090
5 years ago
. "$src"
done
5 years ago
5 years ago
# added by travis gem - should be in ~/.bashrc so not needed to duplicate here
#[ -f /Users/hari.sekhon/.travis/travis.sh ] && source /Users/hari.sekhon/.travis/travis.sh
5 years ago
# shellcheck disable=SC1090
5 years ago
[ -f "$HOME/.bashrc.local" ] && . "$HOME/.bashrc.local"
5 years ago
if [ -d "$HOME/.bash.d" ]; then
5 years ago
shopt -s nullglob
5 years ago
for src in "$HOME/.bash.d/"*.sh; do
. "$src"
done
5 years ago
shopt -u nullglob
5 years ago
fi