#!/usr/bin/env bash # shellcheck disable=SC2230 # vim:ts=4:sts=4:sw=4:et # # Author: Hari Sekhon # Date: circa 2006 (forked from .bashrc) # # 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 # # ============================================================================ # # $ P A T H # ============================================================================ # # general path additions that aren't big enough to have their own .sh file # this is sourced in .bashrc before .bash.d/*.sh because add_PATH() is used extensively everywhere to deduplicate $PATHs across disparate code and also reloads before it gets to this point in the .bash.d/*.sh lexically ordered list if type add_PATHS &>/dev/null && [ -n "${PATHS_SET:-}" ]; then return fi bash_tools="${bash_tools:-$(dirname "${BASH_SOURCE[0]}")/..}" github="${github:-$HOME/github}" # shellcheck disable=SC1090 . "$bash_tools/.bash.d/os_detection.sh" # see the effect of inserting a path like so # PYTHONPATH=/path/to/blah pythonpath pythonpath(){ python -c 'from __future__ import print_function; import sys; [print(_) for _ in sys.path if _]' } # enable this to avoid creating .pyc files (sometimes they trip you up executing outdated python code) # export PYTHONDONTWRITEBYTECODE=1 # see the effect of inserting a path like so # PERL5LIB=/path/to/blah perlpath perlpath(){ perl -e 'print join("\n", @INC);' } # ============================================================================ # #export PATH="${PATH%%:~/github*}" add_PATH(){ local env_var local path if [ $# -gt 1 ]; then env_var="$1" path="$2" else env_var=PATH path="${1:-}" fi path="${path%/}" if ! [[ "${!env_var}" =~ (^|:)$path(:|$) ]]; then # shellcheck disable=SC2140 export "$env_var"="${!env_var}:$path" fi } add_PATH "/bin" add_PATH "/usr/bin" add_PATH "/sbin" add_PATH "/usr/sbin" add_PATH "/usr/local/sbin" add_PATH "/usr/local/bin" add_PATH "$bash_tools" add_PATH ~/bin for x in ~/bin/*; do [ -d "$x" ] || continue add_PATH "$x" done # HomeBrew on Linux if [ -d ~/.linuxbrew/bin ]; then add_PATH ~/.linuxbrew/bin fi # AWS CLI Linux install location if [ -d ~/.local/bin ]; then add_PATH ~/.local/bin fi # AWS SAM CLI Linux install location if [ -d "/home/linuxbrew/.linuxbrew/bin" ]; then add_PATH "/home/linuxbrew/.linuxbrew/bin" fi # do the same with MANPATH #if [ -d ~/man ]; then # MANPATH=~/man${MANPATH:-:} # export MANPATH #fi # added to .bash_profile by SnowSQL installer #if [ -d /Applications/SnowSQL.app/Contents/MacOS ]; then # add_PATH /Applications/SnowSQL.app/Contents/MacOS #fi # ============================================================================ # # A n a c o n d a # ============================================================================ # # Make sure to customize Anaconda installation and de-select Modify Path otherwise it'll change the bash profile # for the 'conda' command add_PATH ~/anaconda/bin # ============================================================================ # # P a r q u e t T o o l s # ============================================================================ # for x in ~/bin/parquet-tools-*; do if [ -d "$x" ]; then add_PATH "$x" fi done if [ -d /usr/local/parquet-tools ]; then add_PATH "/usr/local/parquet-tools" fi # ============================================================================ # # P y t h o n # ============================================================================ # if [ -d ~/Library/Python ]; then for x in ~/Library/Python/*/bin; do [ -d "$x" ] || continue add_PATH "$x" done fi alias lspythonbin='ls -d ~/Library/Python/*/bin/* 2>/dev/null' alias llpythonbin='ls -ld ~/Library/Python/*/bin/* 2>/dev/null' alias lspybin=lspythonbin alias llpybin=llpythonbin # RHEL8 has split python2 / python3 and removed default 'python' :-( if ! type -P python &>/dev/null; then if type -P python2 &>/dev/null; then python(){ python2 "$@"; } elif type -P python3 &>/dev/null; then python(){ python3 "$@"; } fi fi # ============================================================================ # # P e r l # ============================================================================ # #if [ -d /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Perl/ ]; then # add_PATH PERL5LIB /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Perl #fi if [ -d ~/perl5/lib/perl5 ]; then add_PATH PERL5LIB ~/perl5/lib/perl5 fi if [ -d ~/perl5/bin ]; then add_PATH ~/perl5/bin fi alias lsperlbin='ls -d ~/perl5/bin/* 2>/dev/null' alias llperlbin='ls -ld ~/perl5/bin/* 2>/dev/null' # cpanm --local-lib=~/perl5 local::lib # populates a bunch of Perl env vars pointing to ~/perl5/... # eval "$(perl -I ~/perl5/lib/perl5/ -Mlocal::lib)" # ============================================================================ # # N o d e # ============================================================================ # # output from 'npm bin' if [ -d ~/node_modules/.bin ]; then add_PATH ~/node_modules/.bin fi alias lsnodebin='ls -d ~/node_modules/.bin/* 2>/dev/null' alias llnodebin='ls -ld ~/node_modules/.bin/* 2>/dev/null' # ============================================================================ # # R u b y G e m c o m m a n d s # ============================================================================ # # gems will be installed to ~/.gem/ruby/x.y.z/bin # add newest ruby to path first ruby_bins="$(find ~/.gem/ruby -maxdepth 2 -name bin -type d 2>/dev/null)" if isMac; then ruby_bins_newest="$(tail -r <<< "$ruby_bins")" else ruby_bins_newest="$(tac <<< "$ruby_bins")" fi for ruby_bin in $ruby_bins_newest; do add_PATH "$ruby_bin" done unset ruby_bins unset ruby_bins_newest alias lsrubybin='ls -d ~/.gem/ruby/*/bin/* 2>/dev/null' alias llrubybin='ls -ld ~/.gem/ruby/*/bin/* 2>/dev/null' # HomeBrew install on Linux (for AWS SAM CLI) if [ -d ~/.linuxbrew/Homebrew/Library/Homebrew/vendor/portable-ruby/current/bin ]; then add_PATH ~/.linuxbrew/Homebrew/Library/Homebrew/vendor/portable-ruby/current/bin fi # ============================================================================ # # G o l a n g # ============================================================================ # # defined in aliases.sh # shellcheck disable=SC2154 GOPATH="$github/go-tools" if [ -d ~/go/bin ]; then add_PATH ~/go/bin fi # manual installation of 1.5 mismatches with HomeBrew 1.6 installed to $PATH and #export GOROOT="/usr/local/go" # causes: # imports runtime/internal/sys: cannot find package "runtime/internal/sys" in any of: # /usr/local/go/src/runtime/internal/sys (from $GOROOT) # /Users/hari/github/go-tools/src/runtime/internal/sys (from $GOPATH) # shellcheck disable=SC2230 if type -P go &>/dev/null; then if isMac; then GOROOT="$(dirname "$(dirname "$(greadlink -f "$(type -P go)")")")" else GOROOT="$(dirname "$(dirname "$(readlink -f "$(type -P go)")")")" fi export GOROOT add_PATH "$GOROOT/bin" add_PATH "$GOROOT/libexec/bin" add_PATH "$GOPATH/bin" fi alias lsgobin='ls -d ~/go/bin/* "$GOROOT"/{bin,libexec/bin}/* "$GOPATH/bin/"* 2>/dev/null' alias llgobin='ls -ld ~/go/bin/* "$GOROOT"/{bin,libexec/bin}/* "$GOPATH/bin/"* 2>/dev/null' # ============================================================================ # # M y G i t H u b r e p o s # ============================================================================ # # $github defined in aliases.sh # shellcheck disable=SC2154 add_PATH "$github/bash-tools" add_PATH "$github/pytools" add_PATH "$github/tool" add_PATH "$github/tools" add_PATH "$github/go-tools" add_PATH "$github/nagios-plugins" add_PATH "$github/nagios-plugin-kafka" add_PATH "$github/spotify" # ============================================================================ # link_latest(){ # -p suffixes / on dirs, which we grep filter on to make sure we only link dirs # shellcheck disable=SC2010 ls -d -p "$@" | grep "/$" | tail -n 1 | while read -r path; do [ -d "$path" ] || continue #local path_noversion="$( echo "$path" | perl -pn -e 's/-\d+(\.v?\d+)*(-\d+|-[a-z]+)?\/?$//' )" local path_noversion path_noversion="$(perl -pn -e 's/-\d+[\.\w\d-]+\/?$//' <<< "$path")" if [ "$path_noversion" = "$path" ]; then echo "FAILED to strip version, linking back on itself will create a link in subdir" return 1 fi [ -e "$path_noversion" ] && [ ! -L "$path_noversion" ] && continue if isMac; then local ln_opts="-h" else local ln_opts="-T" fi # if you're in 'admin' group on Mac you don't really need to sudo here # shellcheck disable=SC2154 $sudo ln -vfs $ln_opts "$path" "$path_noversion" done } # ============================================================================ # # ============================================================================ # # O l d S t u f f # ============================================================================ # # Most of the stuff below has been migrated to Docker rather than /usr/local installs # ============================================================================ # # A p a c h e D r i l l # ============================================================================ # #link_latest /usr/local/apache-drill-* #export DRILL_HOME=/usr/local/apache-drill #add_PATH "$DRILL_HOME/bin" # ============================================================================ # # M i s c # ============================================================================ # #add_PATH "/usr/local/etcd" #add_PATH "/usr/local/artifactory-oss/bin" #add_PATH "/usr/local/jmeter/bin" #add_PATH "/usr/local/jruby/bin" #add_PATH "/usr/local/jython/bin" #add_PATH "/usr/local/mysql/bin" #add_PATH ~/bin/expect #add_PATH "$RANCID_HOME/bin" #add_PATH /usr/lib/bin/distcc #add_PATH "/usr/lib/nagios/plugins" #add_PATH "/usr/nagios/libexec" #add_PATH "/usr/nagios/libexec/contrib" #if isMac; then # # MacPort and Octave installation # add_PATH /opt/local/bin # # if [ -d "/Applications/VMware Fusion.app/Contents/Library" ]; then # add_PATH "/Applications/VMware Fusion.app/Contents/Library" # fi #fi # ============================================================================ # # C a s s a n d r a # ============================================================================ # #export CASSANDRA_HOME=/usr/local/cassandra #export CCM_HOME=/usr/local/ccm #add_PATH "$CASSANDRA_HOME/bin" #add_PATH "$CASSANDRA_HOME/tools/bin" #add_PATH "$CCM_HOME/bin" # ============================================================================ # # E l a s t i c s e a r c h # ============================================================================ # #export ELASTICSEARCH_HOME=/usr/local/elasticsearch #add_PATH "$ELASTICSEARCH_HOME/bin" # ============================================================================ # # C o u c h b a s e # ============================================================================ # #export COUCHBASE_HOME="/Applications/Couchbase Server.app/Contents/Resources/couchbase-core" #alias cbq="$COUCHBASE_HOME/bin/cbq" #add_PATH "$COUCHBASE_HOME/bin" # ============================================================================ # # G r o o v y # ============================================================================ # # brew install groovy #export GROOVY_HOME=/usr/local/opt/groovy/libexec # brew uninstall groovy # brew install groovysdk #export GROOVY_HOME=/usr/local/opt/groovysdk/libexec # using SDK Man now, sourced at end of private .bashrc # ============================================================================ # # 0 x d a t a H 2 O # ============================================================================ # #export H2O_HOME=/usr/local/h2o #alias h2o="cd $H2O_HOME && java -jar h2o.jar -Xmx1g" # ============================================================================ # # J e t t y # ============================================================================ # #export JETTY_HOME="/usr/local/jetty-hightide" #alias jetty="cd $JETTY_HOME/ && java -jar start.jar" # ============================================================================ # # M e s o s # ============================================================================ # # this breaks parsing if supplying without port and causes duplicate --master switch if supplying the switch manually to mesos-slave or mesos-slave.sh #export MESOS_MASTER=$HOST:5050 # link_latest /usr/local/mesos #export MESOS_HOME=/usr/local/mesos #add_PATH "$MESOS_HOME/bin" #if isMac; then # export MESOS_NATIVE_JAVA_LIBRARY=/usr/local/mesos/src/.libs/libmesos.dylib #else # # check this path # export MESOS_NATIVE_JAVA_LIBRARY=/usr/local/mesos/lib/libmesos.so #fi # deprecated old var #export MESOS_NATIVE_LIBRARY="$MESOS_NATIVE_JAVA_LIBRARY" # ============================================================================ # # M o n g o D B # ============================================================================ # #export MONGO_HOME=/usr/local/mongo #add_PATH "$MONGO_HOME/bin" #add_PATH "$github/mtools" # ============================================================================ # # N e o 4 J # ============================================================================ # #export NEO4J_HOME="/usr/local/neo4j" #add_PATH "$NEO4J_HOME/bin" # ============================================================================ # # S o l r # ============================================================================ # # find /usr/local -type d -name 'apache-solr-*' -maxdepth 1 | while read path; do sudo ln -vfsh "$path" "${path%%-*}"; done # link_latest '/usr/local/apache-solr-*' # ln -vsf /usr/local/apache-solr /usr/local/solr # 3.x #export SOLR_HOME=/usr/local/apache-solr # 4.x #export SOLR_HOME=/usr/local/solr #export APACHE_SOLR_HOME="$SOLR_HOME" #add_PATH "$SOLR_HOME/bin" #add_PATH "$SOLR_HOME/example/scripts/cloud-scripts" # ============================================================================ # # S t o r m # ============================================================================ # #export STORM_HOME=/usr/local/storm #add_PATH "$STORM_HOME/bin" # ============================================================================ # # T a c h y o n # ============================================================================ # #export TACHYON_HOME=/usr/local/tachyon #add_PATH "$TACHYON_HOME/bin" # ============================================================================ # # B a s h o R i a k # ============================================================================ # #export RIAK_HOME=/usr/local/riak #add_PATH "$RIAK_HOME/bin" # ============================================================================ # # S c a l a # ============================================================================ # #add_PATH "/usr/local/scala/bin" # ============================================================================ # # S p a r k # ============================================================================ # #export SPARK_HOME=/usr/local/spark #add_PATH "$SPARK_HOME/bin" # ============================================================================ # # S o n a r Q u b e # ============================================================================ # #export SONAR_SCANNER_HOME=/usr/local/sonar-scanner #add_PATH "$SONAR_SCANNER_HOME/bin" # ============================================================================ # # TypeSafe Activator - Akka, Play # ============================================================================ # # link_latest /usr/local/activator-dist-* #export ACTIVATOR_HOME=/usr/local/activator-dist #add_PATH "$ACTIVATOR_HOME" export PATHS_SET=1