forked from fsquillace/pearl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpearl
executable file
·216 lines (165 loc) · 5.83 KB
/
pearl
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
#!/bin/sh
# pearl by Filippo Squillace
# (great update 16-12-2009 date of my last exam in UNICAL :)
# (update 21-07-2010 one of my last days in Valencia §:( )
# (update 07-01-2012 ending the thesis in Valencia)
# (update 29-01-2012 continue ending thesis in Valencia)
# (update 27-01-2013 working in Dublin)
# (update 06-02-2013 still in Dublin and big day changing the name in pearl!)
# Usage: source pearl OR bash --rcfile pearl
# If not running interactively, don't do anything
[ -z "$PS1" ] && return
[[ $- != *i* ]] && return
if [ "${BASH_ARGV}" = "" ]; then
echo "Error the correct usage is: source $0 OR bash --rcfile $0"
exit 128
fi
# make less more friendly for non-text input files, see lesspipe(1)
[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)"
# Possible choices:
#umask file mode directory mode
#0022 -rw-r--r-- drwxr-xr-x
#0077 -rw------- drwx------
umask 0022
# Define the main pearl variables
export PEARL_ROOT=$(dirname $(readlink -f "${BASH_ARGV[0]}"))
export PEARL_HOME=~/.config/pearl
export PEARL_TEMPORARY=$PEARL_HOME/tmp/`tty`
mkdir -p $PEARL_TEMPORARY
# Variable for logging system
export PEARL_DEBUG=0
# Import the functions from misc.sh and install.sh
source $PEARL_ROOT/lib/misc.sh
source $PEARL_ROOT/lib/install.sh
# Install pearl if it is not installed yet
pearl_install
#####################
# Variables
#####################
export SYNC_HOME=~/Dropbox/
export PYTHONPATH=$PYTHONPATH:$PEARL_ROOT/lib
PATH=${PEARL_ROOT}/bin:${PATH}
export EDITOR=vim
export VISUAL=$EDITOR # some programs use this instead of EDITOR
export MANPATH=$MANPATH:$PEARL_ROOT/man
# HIST variables
export HISTFILESIZE=100000
export HISTSIZE=100000
export HISTIGNORE="&:l[las]:[bf]g:l:a:j:f:b:e"
export HISTCONTROL=erasedups:ignorespace
#######################
#@@@@@@@@@@@@@@@@@@
#@@ Aliases
#@@@@@@@@@@@@@@@@@@
# Mini-aliases :)
alias j="jobs"
alias f="fg"
alias b="bg"
alias q="exit"
alias ls="/bin/ls --color=auto"
# Only the newer version of ls support the option --group-directories-first
ls --group-directories-first &> /dev/null
if [ "$?" -eq 0 ]; then
alias l="ls --group-directories-first --color=auto -h"
else
alias l="ls --color=auto -h"
fi
alias a="ls -ha"
alias c="clear"
alias e='$EDITOR'
alias p='pwd'
alias h='history'
alias t='tree'
alias ll="l -l"
alias la="a -l"
alias share="cd ${PEARL_ROOT}/share"
alias home="cd ${HOME}"
alias ~="cd ${HOME}"
alias etc="cd ${PEARL_ROOT}/etc"
alias bin="cd ${PEARL_ROOT}/bin"
# Allows to keep aliases in sudo
alias sudo="sudo "
#alias sudo="sudo -E" # Useful to keep variables environment when you are root
alias go="ping 8.8.8.8"
alias goo="ping www.google.it"
alias isconnect="python -c \"import util.net;print(util.net.is_connect())\""
# Grep-based aliases
alias grep='grep --color=auto'
alias fgrep='fgrep --color=auto'
alias egrep='egrep --color=auto'
# Looks up to the history
alias hgrep='history | /usr/bin/grep -i'
# Add an "alert" alias for long running commands. Use like so:
# sleep 10; alert
alias alert='notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "$(history|tail -n1|sed -e '\''s/^\s*[0-9]\+\s*//;s/[;&|]\s*alert$//'\'')"'
# Open screen+irssi
alias scrssi="screen -S scrssi -aARd -c ${PEARL_ROOT}/etc/screenrc -t irssi irssi; clear"
# If the system has htop use it!
[ -e /usr/bin/htop ] && alias top="/usr/bin/htop"
#@@@@@@@@@@@@@@@@@@@
#>>>>>>>>>>>>>>>>>>>
#>> Prompt
#>>>>>>>>>>>>>>>>>>>
# Colorize the hostname
hstcol=$(hostname | sum - | awk '{print 31 + $0 % 6}')
prompt="\[\033[01;31m\][\$(if [[ \$? == 0 ]]; then echo \"\[\033[01;32m\]\342\234\223\"; else echo \"\[\033[01;31m\]\342\234\227\"; fi) \[\033[1;32m\]\t \[\033[1;33m\]\j \[\033[01;31m\]\u@\[\033[01;${hstcol}m\]\h \[\033[01;34m\]\W \[\033[01;35m\]\$\[\033[01;31m\]]> \[\033[00m\]"
if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then
# We have color support; assume it's compliant with Ecma-48
# (ISO/IEC-6429). (Lack of such support is extremely rare, and such
# a case would tend to support setf rather than setaf.)
PS1=$prompt
fi
PROMPT_COMMAND="history -a;$PROMPT_COMMAND" # immediately insert history into history file
case ${TERM} in
xterm*|rxvt*|Eterm|aterm|kterm|gnome*|vt100)
PS1=$prompt
#PROMPT_COMMAND=${PROMPT_COMMAND:+$PROMPT_COMMAND; }'printf "\033_%s@%s:%s\033\\" "${USER}" "${HOSTNAME%%.*}" "${PWD/#$HOME/~}"'
;;
screen)
PS1=$prompt
;;
*)
;;
esac
unset prompt hstcol
#>>>>>>>>>>>>>>>>>>>>>
#*******************
#** Bash options
#*******************
shopt -s cdspell &> /dev/null
shopt -s autocd &> /dev/null
shopt -s dirspell &> /dev/null
# append to the history file, don't overwrite it
shopt -s histappend &> /dev/null
# check the window size after each command and, if necessary,
# update the values of LINES and COLUMNS.
shopt -s checkwinsize &> /dev/null
#*********************
#########################
# MISC
#########################
#*** Handle to clean temp directory
trap "/bin/rm -fr $PEARL_TEMPORARY" QUIT EXIT ABRT KILL TERM
#******* Script to trap USR1 signal in order to handle changing directory
function sigusr2()
{
source $PEARL_TEMPORARY/new_cmd
}
trap "sigusr2" USR2 # catch -USR2 signal
# Load the LS_COLORS configuration
[ -f $PEARL_ROOT/etc/LS_COLORS ] && eval $(dircolors -b $PEARL_ROOT/etc/LS_COLORS)
# This binds Ctrl-O to ranger:
bind '"\C-o":"\C-u\C-k ranger\C-m"'
# Alias definitions.
# You may want to put all your additions into a separate file like
# ~/.bash_aliases, instead of adding them here directly.
# See /usr/share/doc/bash-doc/examples in the bash-doc package.
if [ -f ~/.bash_aliases ]; then
. ~/.bash_aliases
fi
# enable programmable completion features (you don't need to enable
# this, if it's already enabled in /etc/bash.bashrc and /etc/profile
# sources /etc/bash.bashrc).
if [ -f /etc/bash_completion ] && ! shopt -oq posix; then
. /etc/bash_completion
fi