Update importante
[dotfilesold/.git] / .bashrc
1 # ~/.bashrc: executed by bash(1) for non-login shells.
2 # see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
3 # for examples
4 export EDITOR=vim;
5 export VISUAL=vim; #Nano is the main editor
6 # If not running interactively, don't do anything
7 case $- in
8     *i*) ;;
9       *) return;;
10 esac
11
12 # don't put duplicate lines or lines starting with space in the history.
13 # See bash(1) for more options
14 HISTCONTROL=ignoreboth
15
16 # append to the history file, don't overwrite it
17 shopt -s histappend
18
19 # for setting history length see HISTSIZE and HISTFILESIZE in bash(1)
20 HISTSIZE=
21 HISTFILESIZE=
22 export HISTIGNORE='&:ls:ll:la:cd:exit:clear:history'
23 # check the window size after each command and, if necessary,
24 # update the values of LINES and COLUMNS.
25 shopt -s checkwinsize
26
27 # If set, the pattern "**" used in a pathname expansion context will
28 # match all files and zero or more directories and subdirectories.
29 #shopt -s globstar
30
31 # make less more friendly for non-text input files, see lesspipe(1)
32 [ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)"
33
34 # set variable identifying the chroot you work in (used in the prompt below)
35 if [ -z "${debian_chroot:-}" ] && [ -r /etc/debian_chroot ]; then
36     debian_chroot=$(cat /etc/debian_chroot)
37 fi
38
39 # set a fancy prompt (non-color, unless we know we "want" color)
40 case "$TERM" in
41     xterm-color|*-256color) color_prompt=yes;;
42 esac
43
44 # uncomment for a colored prompt, if the terminal has the capability; turned
45 # off by default to not distract the user: the focus in a terminal window
46 # should be on the output of commands, not on the prompt
47 #force_color_prompt=yes
48
49 if [ -n "$force_color_prompt" ]; then
50     if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then
51         # We have color support; assume it's compliant with Ecma-48
52         # (ISO/IEC-6429). (Lack of such support is extremely rare, and such
53         # a case would tend to support setf rather than setaf.)
54         color_prompt=yes
55     else
56         color_prompt=
57     fi
58 fi
59
60 if [ "$color_prompt" = yes ]; then
61     PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
62 else
63     PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
64 fi
65 unset color_prompt force_color_prompt
66
67 # If this is an xterm set the title to user@host:dir
68 case "$TERM" in
69 xterm*|rxvt*|alacritty)
70     PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1"
71     ;;
72 *)
73     ;;
74 esac
75
76 # enable color support of ls and also add handy aliases
77 if [ -x /usr/bin/dircolors ]; then
78     test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
79     alias ls='ls -hN --color=auto --group-directories-first'
80     #alias dir='dir --color=auto'
81     #alias vdir='vdir --color=auto'
82
83     alias grep='grep --color=auto'
84     alias fgrep='fgrep --color=auto'
85     alias egrep='egrep --color=auto'
86 fi
87
88 # colored GCC warnings and errors
89 #export GCC_COLORS='error=01;31:warning=01;35:note=01;36:caret=01;32:locus=01:quote=01'
90
91 # some more ls aliases
92 alias ll='ls -alF'
93 alias la='ls -A'
94 alias l='ls -CF'
95
96 # Add an "alert" alias for long running commands.  Use like so:
97 #   sleep 10; alert
98 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$//'\'')"'
99
100 # Alias definitions.
101 # You may want to put all your additions into a separate file like
102 # ~/.bash_aliases, instead of adding them here directly.
103 # See /usr/share/doc/bash-doc/examples in the bash-doc package.
104
105 if [ -f ~/.bash_aliases ]; then
106     . ~/.bash_aliases
107 fi
108
109 # enable programmable completion features (you don't need to enable
110 # this, if it's already enabled in /etc/bash.bashrc and /etc/profile
111 # sources /etc/bash.bashrc).
112 if ! shopt -oq posix; then
113   if [ -f /usr/share/bash-completion/bash_completion ]; then
114     . /usr/share/bash-completion/bash_completion
115   elif [ -f /etc/bash_completion ]; then
116     . /etc/bash_completion
117   fi
118 fi
119 # vi mode in the shell
120 set -o vi
121 # transform md anotations into PDF
122 mdpdf () { pandoc "$1".md -t beamer -o "$1".pdf ;}
123 #byebye for shutdown
124 alias byebye='shutdown now'
125 # Get all metadata
126 metadata () { echo "Salida del comando stat" ; stat "$1" ; echo "Salida del comando ls -lisan" ; ls -lisan "$1" ; echo "salida del comando exiftool" ; exiftool "$1" ;}
127 # use highlight for colored cat
128 alias ccat='highlight --out-format=ansi'
129 # activates the autocd mode
130 shopt -s autocd
131 # wifi available
132 alias wifi='nmcli d wifi'
133 # personalized ps1
134 export PS1="\[\e]0;\u@\h: \w\a\]${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\n\$"
135 alias autowal='wal --iterative -i /usr/share/backgrounds/ > /dev/null'
136 #figlet de mi nombre
137 whoami | figlet Josuer08 | lolcat -F 0.25;
138 #whoami | figlet Josuer08 | lolcat;
139 # agragando el comando gitdotfiles para manejar los dotfiles
140 alias gitdotfiles='/usr/bin/git --git-dir=$HOME/Documents/dotfiles/ --work-tree=$HOME';
141
142 function cdls() {
143     DIR="$*";
144         # if no DIR given, go home
145         if [ $# -lt 1 ]; then
146                 DIR=$HOME;
147     fi;
148     builtin cd "${DIR}" && \
149     # use your preferred ls command
150         ls -F --color=auto
151 }
152
153
154
155
156
157
158 #colorman
159 if $_isxrunning; then
160   export PAGER=less
161   export LESS_TERMCAP_mb=$'\E[01;31m'       # begin blinking
162   export LESS_TERMCAP_md=$'\E[01;38;5;74m'  # begin bold
163   export LESS_TERMCAP_me=$'\E[0m'           # end mode
164   export LESS_TERMCAP_se=$'\E[0m'           # end standout-mode
165   export LESS_TERMCAP_so=$'\E[38;5;246m'    # begin standout-mode - info box
166   export LESS_TERMCAP_ue=$'\E[0m'           # end underline
167   export LESS_TERMCAP_us=$'\E[04;38;5;146m' # begin underline
168 fi
169 #top10 commands
170 top10() { history | awk '{a[$2]++ } END{for(i in a){print a[i] " " i}}' | sort -rn | head; }
171 # goes up by the number of directories
172 up() {
173   local d=""
174   limit=$1
175   for ((i=1 ; i <= limit ; i++)); do
176     d=$d/..
177   done
178   d=$(echo $d | sed 's/^\///')
179   if [[ -z "$d" ]]; then
180     d=..
181   fi
182   cd $d
183 }
184 # ARCHIVE EXTRACTOR {{{
185 extract() {
186   clrstart="\033[1;34m"  #color codes
187   clrend="\033[0m"
188
189   if [[ "$#" -lt 1 ]]; then
190     echo -e "${clrstart}Pass a filename. Optionally a destination folder. You can also append a v for verbose output.${clrend}"
191     exit 1 #not enough args
192   fi
193
194   if [[ ! -e "$1" ]]; then
195     echo -e "${clrstart}File does not exist!${clrend}"
196     exit 2 #file not found
197   fi
198
199   if [[ -z "$2" ]]; then
200     DESTDIR="." #set destdir to current dir
201   elif [[ ! -d "$2" ]]; then
202     echo -e -n "${clrstart}Destination folder doesn't exist or isnt a directory. Create? (y/n): ${clrend}"
203     read response
204     #echo -e "\n"
205     if [[ $response == y || $response == Y ]]; then
206       mkdir -p "$2"
207       if [ $? -eq 0 ]; then
208         DESTDIR="$2"
209       else
210         exit 6 #Write perms error
211       fi
212     else
213       echo -e "${clrstart}Closing.${clrend}"; exit 3 # n/wrong response
214     fi
215   else
216     DESTDIR="$2"
217   fi
218
219   if [[ ! -z "$3" ]]; then
220     if [[ "$3" != "v" ]]; then
221       echo -e "${clrstart}Wrong argument $3 !${clrend}"
222       exit 4 #wrong arg 3
223     fi
224   fi
225
226   filename=`basename "$1"`
227
228   #echo "${filename##*.}" debug
229
230   case "${filename##*.}" in
231     tar)
232       echo -e "${clrstart}Extracting $1 to $DESTDIR: (uncompressed tar)${clrend}"
233       tar x${3}f "$1" -C "$DESTDIR"
234       ;;
235     gz)
236       echo -e "${clrstart}Extracting $1 to $DESTDIR: (gip compressed tar)${clrend}"
237       tar x${3}fz "$1" -C "$DESTDIR"
238       ;;
239     tgz)
240       echo -e "${clrstart}Extracting $1 to $DESTDIR: (gip compressed tar)${clrend}"
241       tar x${3}fz "$1" -C "$DESTDIR"
242       ;;
243     xz)
244       echo -e "${clrstart}Extracting  $1 to $DESTDIR: (gip compressed tar)${clrend}"
245       tar x${3}f -J "$1" -C "$DESTDIR"
246       ;;
247     bz2)
248       echo -e "${clrstart}Extracting $1 to $DESTDIR: (bzip compressed tar)${clrend}"
249       tar x${3}fj "$1" -C "$DESTDIR"
250       ;;
251     zip)
252       echo -e "${clrstart}Extracting $1 to $DESTDIR: (zipp compressed file)${clrend}"
253       unzip "$1" -d "$DESTDIR"
254       ;;
255     rar)
256       echo -e "${clrstart}Extracting $1 to $DESTDIR: (rar compressed file)${clrend}"
257       unrar x "$1" "$DESTDIR"
258       ;;
259     7z)
260       echo -e  "${clrstart}Extracting $1 to $DESTDIR: (7zip compressed file)${clrend}"
261       7za e "$1" -o"$DESTDIR"
262       ;;
263     *)
264       echo -e "${clrstart}Unknown archieve format!"
265       exit 5
266       ;;
267   esac
268 }
269 #}}}
270
271
272
273 # REMIND ME, ITS IMPORTANT! {{{
274 # usage: remindme <time> <text>
275 # e.g.: remindme 10m "omg, the pizza"
276 remindme() {
277   if [[ "$#" -lt 2 ]]; then
278     echo -e "Usage: remindme [time] '[message]'"
279     echo -e "Example: remindme 50s 'check mail'"
280     echo -e "Example: remindme 10m 'go to class'"
281     #exit 0 #not enough args
282   fi
283   if [[ "$#" -gt 2 ]]; then
284     echo -e "Usage: remindme [time] '[message]'"
285     echo -e "Example: remindme 50s 'check mail'"
286     echo -e "Example: remindme 10m 'go to class'"
287     #exit 0 #more than enough args
288   fi
289   if  [[ "$#" == 2 ]]; then
290     sleep $1 && notify-send -t 15000 "$2" & echo 'Reminder set'
291   fi
292   }
293
294 #}}}
295
296 ### add to xterm
297 xrdb -merge ~/.Xresources >> /dev/null 2>&1