/ init.bash
init.bash
1 #@IgnoreInspection BashAddShebang 2 3 # Make sure only to init once 4 if [[ -z "$__MY_BASH_INIT_FLAG" ]] ; then 5 __MY_BASH_INIT_FLAG="initializing" 6 7 # We should move to the script dir 8 # Since this isn't possible using $0 we need our own var :/ 9 pushd $MY_BASH_INIT_DIR > /dev/null 10 11 # Set the title of the containing terminal emulator 12 # Chapter `Window Titles` in `man xterm` 13 printf '\033]2;'$(hostname)'\007' 14 15 # 16 # Sources all files ending in .bash in the given subfolder 17 # 18 sourceFolder(){ 19 local folder=$1 20 # import functions 21 if [ -d "$folder" ] ; then 22 pushd $folder > /dev/null 23 for file in `find -maxdepth 1 -type f -name "*.bash"`; do 24 source "$file" 25 done 26 popd > /dev/null 27 fi 28 } 29 30 # 31 # import functions 32 # 33 sourceFolder "aliases/" 34 sourceFolder "exports/" 35 sourceFolder "functions/" 36 sourceFolder "completions/" 37 38 39 # 40 # add custom commands 41 # 42 __USER_BIN="$HOME/bin" 43 if ! [ -d "$__USER_BIN" ] ; then 44 mkdir "$__USER_BIN" 45 fi 46 47 # set PATH so it includes user's private bin if it exists 48 # AND isn't set yet 49 if [ -d "$__USER_BIN" ] && ! (echo "$PATH" | tr : '\n' | grep -E "^${__USER_BIN}$" > /dev/null ) ; then 50 PATH="$__USER_BIN:$PATH" 51 fi 52 PATH="$PATH:$MY_BASH_INIT_DIR/bin" 53 54 55 # Installed programs using the ~/.local prefix 56 if [ -d "$HOME/.local/bin" ] ; then 57 PATH="$HOME/.local/bin:$PATH" 58 fi 59 60 export HISTCONTROL="ignoredups:ignorespace" 61 62 # 63 # Set shopts 64 # https://www.gnu.org/software/bash/manual/bashref.html#The-Shopt-Builtin 65 # 66 67 # If set, a command name that is the name of a directory is executed as if it were the argument to the cd command. This option is only used by interactive shells 68 shopt -s autocd 69 70 # Fix the damn globs 71 # If set, the pattern ‘**’ used in a filename expansion context will match all files and zero or more directories and subdirectories. If the pattern is followed by a ‘/’, only directories and subdirectories match 72 shopt -s globstar 73 74 # Only for interactive shells 75 if [[ -n "$PS1" ]] ; then 76 # Custom key-bindings 77 bind -f inputrc 78 79 # Ctr+C deletes the line 80 # https://unix.stackexchange.com/questions/376153/how-can-one-override-bash-ctrlc-to-be-more-fish-like 81 trap 'tput dl1; tput cuu1; tput dl1; tput cuu1' SIGINT 82 83 # 84 # set the commandline format and color 85 # 86 if [ -e "PS.bash" ] ; then 87 source PS.bash 88 fi 89 90 # 91 # Extra stuff if it exists 92 # Useful for nix package to add generated env vars, etc 93 # 94 if [ -e "extra_interactive.bash" ] ; then 95 source "extra_interactive.bash" 96 fi 97 else 98 # 99 # Extra stuff if it exists 100 # Useful for nix package to add generated env vars, etc 101 # 102 if [ -e "extra_noninteractive.bash" ] ; then 103 source "extra_noninteractive.bash" 104 fi 105 fi 106 107 # 108 # Extra stuff if it exists 109 # Useful for nix package to add generated env vars, etc 110 # 111 if [ -e "extra.bash" ] ; then 112 source "extra.bash" 113 fi 114 115 popd > /dev/null 116 117 # Indicator that we're done initializing 118 __MY_BASH_INIT_FLAG="initialized" 119 fi