silas / config

Profile management

This URL has Read+Write access

config / .bash_profile
100644 220 lines (183 sloc) 4.853 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
################################################################################
# Helper Functions
################################################################################
 
function command_exists {
  if command -v "$1" &>/dev/null; then
    return 0
  else
    return 1
  fi
}
 
function extend_path {
  if [[ $PATH != *:$1* ]]; then
    export PATH="$PATH:$1"
  fi
}
 
function random_line {
  LINES=$( wc -l "$1" | awk '{ print ($1 + 1) }' )
  RANDSEED=$( date '+%S%M%I' )
  LINE=$( cat "$1" | awk -v "COUNT=$LINES" -v "SEED=$RANDSEED" 'BEGIN { srand(SEED); i=int(rand()*COUNT) } FNR==i { print $0 }' )
  echo "$LINE"
}
 
function string_slice {
  STRING="$1"
  declare -i LENGTH="${#STRING}"
  declare -i START="$2"
  declare -i END="$3"
  if [ $START -lt 0 ]; then
    START=$[ $LENGTH + $START ]
  fi
  if [ $END -le 0 ]; then
    END=$[ $LENGTH + $END ]
  fi
  START=$[ $START + 1 ]
  (echo "$STRING" | cut -c $START-$END) 2> /dev/null
}
 
################################################################################
# Setttings
################################################################################
 
alias config="git --git-dir=$HOME/.config.git/ --work-tree=$HOME"
alias fedora='ssh silas@fedorapeople.org'
alias ll='ls -lh'
alias lr='ls -R'
alias nc='nc -v'
alias reload="source $HOME/.bash_profile"
alias root="sudo bash --init-file $HOME/.bash_profile"
alias sdf='ssh silas@tty.freeshell.net'
alias srpm='rpmbuild -bs --nodeps'
alias vi='echo Just type vim, it will save you time in the long run.'
 
export CDPATH=':..:~:~/resources'
export CVS_RSH='ssh'
export CVSROOT=':ext:silas@cvs.fedoraproject.org:/cvs/pkgs'
export EDITOR='vim'
export HISTCONTROL='ignoreboth'
export LSCOLORS="ExGxBxDxCxEgEdxbxgxcxd"
export PS1='[\u@\h \W]$ '
export PYTHON='/usr/bin/env python'
 
extend_path "$HOME/.local/bin"
 
set -o vi
 
shopt -s checkwinsize
shopt -s histappend
 
################################################################################
# Functions
################################################################################
 
function archive {
  DIR="$HOME/Backup/$(date +%y/%m/%d)"
  mkdir -p "$DIR" && mv "$1" "$DIR/"
}
 
function backup {
  DIR="$HOME/Backup/$(date +%y/%m/%d)"
  mkdir -p "$DIR" && cp -r "$1" "$DIR/"
}
 
function dns_clear {
  case "$PLATFORM" in
    'darwin')
      dscacheutil -flushcache ;;
    *)
      echo Not supported ;;
  esac
}
 
function get {
  case "$PLATFORM" in
    'darwin')
      curl -O "$1" ;;
    *)
      wget "$1" ;;
  esac
}
 
function predate {
  mv "$1" "$(date +%Y-%m-%d)-$1"
}
 
function profile {
  "$EDITOR" "$HOME/.bash_profile"
  reload
}
 
function python {
  if [[ -n "$1" ]]; then
    $PYTHON $@
  elif command_exists 'ipython'; then
    ipython
  else
    $PYTHON
  fi
}
 
function rpm-extract {
  rpm2cpio "$1" | cpio -idmv
}
 
function tip {
  echo `random_line "$HOME/.tips"`
}
 
function update {
  if command_exists 'git'; then
    config commit -a --untracked-files=no
    config pull
    config push
    reload
  else
    echo 'Please install Git.'
  fi
}
 
################################################################################
# OS specific settings
################################################################################
 
function load_darwin {
  export PLATFORM='darwin'
 
  # Fix screen
  alias ls='ls -G'
  alias screen="export SCREENPWD=$(pwd); /usr/bin/screen"
  export SHELL="/bin/bash -rcfile $HOME/.bash_profile"
 
  # Switch to current working directory when screen is started
  if [[ "$TERM" == 'screen' ]]; then
    cd "$SCREENPWD"
  fi
 
  # Load Fink on OS X
  if [[ -r /sw/bin/init.sh ]]; then
    . /sw/bin/init.sh
  fi
 
  # Enable programmable completion (if available)
  if [ -f /sw/etc/bash_completion ]; then
    . /sw/etc/bash_completion
  else
    echo "No bash completion."
  fi
}
 
function load_freebsd {
  export PLATFORM='freebsd'
}
 
function load_linux {
  export PLATFORM='linux'
  extend_path '/sbin'
  extend_path '/usr/sbin'
  extend_path '/usr/local/sbin'
 
  # Enable programmable completion (if available)
  if [ -f /etc/bash_completion ]; then
    . /etc/bash_completion
  else
    echo "No bash completion."
  fi
}
 
function load_netbsd {
  export PLATFORM='netbsd'
}
 
# Load OS specific settings
case "`uname`" in
  'Darwin')
    load_darwin ;;
  'FreeBSD')
    load_freebsd ;;
  'Linux')
    load_linux ;;
  'NetBSD')
    load_netbsd ;;
esac
 
################################################################################
# Local environment
################################################################################
 
# Load local configuration settings
if [ -f "$HOME/.bash_local" ]; then
  . "$HOME/.bash_local"
fi
 
################################################################################
# Run at start
################################################################################
 
tip