Giant blob of minor changes
[dotfiles/.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
35 # If this is an xterm set the title to user@host:dir
36 #case "$TERM" in
37 #xterm*|rxvt*|alacritty)
38     #PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1"
39     #;;
40 #*)
41     #;;
42 #esac
43
44 # enable color support of ls and also add handy aliases
45 if [ -x /usr/bin/dircolors ]; then
46     test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
47     alias ls='ls -hN --color=auto --group-directories-first'
48     #alias dir='dir --color=auto'
49     #alias vdir='vdir --color=auto'
50
51     alias grep='grep --color=auto'
52     alias fgrep='fgrep --color=auto'
53     alias egrep='egrep --color=auto'
54 fi
55
56 # colored GCC warnings and errors
57 #export GCC_COLORS='error=01;31:warning=01;35:note=01;36:caret=01;32:locus=01:quote=01'
58
59 # some more ls aliases
60 alias ll='ls -alF'
61 alias la='ls -A'
62 alias l='ls -CF'
63
64 # Add an "alert" alias for long running commands.  Use like so:
65 #   sleep 10; alert
66 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$//'\'')"'
67
68 # Alias definitions.
69 # You may want to put all your additions into a separate file like
70 # ~/.bash_aliases, instead of adding them here directly.
71 # See /usr/share/doc/bash-doc/examples in the bash-doc package.
72
73 if [ -f ~/.bash_aliases ]; then
74     . ~/.bash_aliases
75 fi
76
77 # enable programmable completion features (you don't need to enable
78 # this, if it's already enabled in /etc/bash.bashrc and /etc/profile
79 # sources /etc/bash.bashrc).
80 if ! shopt -oq posix; then
81   if [ -f /usr/share/bash-completion/bash_completion ]; then
82     . /usr/share/bash-completion/bash_completion
83   elif [ -f /etc/bash_completion ]; then
84     . /etc/bash_completion
85   fi
86 fi
87 # vi mode in the shell
88 set -o vi
89 # autocomplete for sudo man and wich
90 complete -cf sudo man wich;
91 # transform md anotations into PDF
92 mdpdf () { pandoc "$1".md -t beamer -o "$1".pdf ;}
93 #byebye for shutdown
94 alias byebye='shutdown now'
95 # Get all metadata
96 metadata () { echo "Salida del comando stat" ; stat "$1" ; echo "Salida del comando ls -lisan" ; ls -lisan "$1" ; echo "salida del comando exiftool" ; exiftool "$1" ;}
97 # use highlight for colored cat
98 alias ccat='highlight --out-format=ansi'
99 # activates the autocd mode
100 shopt -s autocd
101 # wifi available
102 alias wifi='nmcli d wifi'
103
104 # personalized ps1 #################################################################################
105 # .bashrc (or .bash_profile)
106
107 # declares an array with the emojis we want to support
108 EMOJIS=(👻 💀 👽 👾 🎃 😎 🧠 🦘 🦍 🎻)
109
110 # selects a random element from the EMOJIS set
111 SELECTED_EMOJI=${EMOJIS[$RANDOM % ${#EMOJIS[@]}]};
112 # declare the terminal prompt format
113 #export PS1='${SELECTED_EMOJI}  [\u@\h \W]$ '
114 #export PS1="\e[1;90m[\$?]\e[m\e[1;92m\[$(tput bold)\]\u@\h\e[m\[$(tput sgr0)\]:\e[0;36m\w\e[m\n\\$";
115 export PS1="\e[1;90m[\$?]\e[m\e[1;92m\[$(tput bold)\]\u@\h\e[m\[$(tput sgr0)\]:\e[0;36m\w\e[m\n${SELECTED_EMOJI}";
116
117
118 ####################################################################################################
119
120 cat ~/.cache/wal/sequences & #This imports the theme from the last pywal
121
122
123 #export PS1="\[\033[38;5;247m\][\$?]\[$(tput sgr0)\]\[$(tput bold)\]\[\033[38;5;40m\]\u@\h\[$(tput sgr0)\]:\[$(tput sgr0)\]\[\033[38;5;45m\]\w\[$(tput sgr0)\]\n\\$\[$(tput sgr0)\]"
124
125 alias autowal='wal --iterative -i /usr/share/backgrounds/ > /dev/null'
126 #figlet de mi nombre
127 whoami | figlet Josuer08 | lolcat -F 0.25;
128 #whoami | figlet Josuer08 | lolcat;
129 # agragando el comando gitdotfiles para manejar los dotfiles
130 alias gitdotfiles='/usr/bin/git --git-dir=$HOME/Documents/dotfiles/ --work-tree=$HOME';
131
132 function cdls() {
133     DIR="$*";
134         # if no DIR given, go home
135         if [ $# -lt 1 ]; then
136                 DIR=$HOME;
137     fi;
138     builtin cd "${DIR}" && \
139     # use your preferred ls command
140         ls -F --color=auto
141 }
142
143
144 #vicat is a color and line number cat
145
146 function vicat() {
147   ccat $@ | nl;
148
149 }
150
151
152
153 #colorman
154 if $_isxrunning; then
155   export PAGER=less
156   export LESS_TERMCAP_mb=$'\E[01;31m'       # begin blinking
157   export LESS_TERMCAP_md=$'\E[01;38;5;74m'  # begin bold
158   export LESS_TERMCAP_me=$'\E[0m'           # end mode
159   export LESS_TERMCAP_se=$'\E[0m'           # end standout-mode
160   export LESS_TERMCAP_so=$'\E[38;5;246m'    # begin standout-mode - info box
161   export LESS_TERMCAP_ue=$'\E[0m'           # end underline
162   export LESS_TERMCAP_us=$'\E[04;38;5;146m' # begin underline
163 fi
164 #top10 commands
165 top10() { history | awk '{a[$2]++ } END{for(i in a){print a[i] " " i}}' | sort -rn | head; }
166 # goes up by the number of directories
167 up() {
168   local d=""
169   limit=$1
170   for ((i=1 ; i <= limit ; i++)); do
171     d=$d/..
172   done
173   d=$(echo $d | sed 's/^\///')
174   if [[ -z "$d" ]]; then
175     d=..
176   fi
177   cd $d
178 }
179 # ARCHIVE EXTRACTOR {{{
180 extract() {
181   clrstart="\033[1;34m"  #color codes
182   clrend="\033[0m"
183
184   if [[ "$#" -lt 1 ]]; then
185     echo -e "${clrstart}Pass a filename. Optionally a destination folder. You can also append a v for verbose output.${clrend}"
186     exit 1 #not enough args
187   fi
188
189   if [[ ! -e "$1" ]]; then
190     echo -e "${clrstart}File does not exist!${clrend}"
191     exit 2 #file not found
192   fi
193
194   if [[ -z "$2" ]]; then
195     DESTDIR="." #set destdir to current dir
196   elif [[ ! -d "$2" ]]; then
197     echo -e -n "${clrstart}Destination folder doesn't exist or isnt a directory. Create? (y/n): ${clrend}"
198     read response
199     #echo -e "\n"
200     if [[ $response == y || $response == Y ]]; then
201       mkdir -p "$2"
202       if [ $? -eq 0 ]; then
203         DESTDIR="$2"
204       else
205         exit 6 #Write perms error
206       fi
207     else
208       echo -e "${clrstart}Closing.${clrend}"; exit 3 # n/wrong response
209     fi
210   else
211     DESTDIR="$2"
212   fi
213
214   if [[ ! -z "$3" ]]; then
215     if [[ "$3" != "v" ]]; then
216       echo -e "${clrstart}Wrong argument $3 !${clrend}"
217       exit 4 #wrong arg 3
218     fi
219   fi
220
221   filename=`basename "$1"`
222
223   #echo "${filename##*.}" debug
224
225   case "${filename##*.}" in
226     tar)
227       echo -e "${clrstart}Extracting $1 to $DESTDIR: (uncompressed tar)${clrend}"
228       tar x${3}f "$1" -C "$DESTDIR"
229       ;;
230     gz)
231       echo -e "${clrstart}Extracting $1 to $DESTDIR: (gip compressed tar)${clrend}"
232       tar x${3}fz "$1" -C "$DESTDIR"
233       ;;
234     tgz)
235       echo -e "${clrstart}Extracting $1 to $DESTDIR: (gip compressed tar)${clrend}"
236       tar x${3}fz "$1" -C "$DESTDIR"
237       ;;
238     xz)
239       echo -e "${clrstart}Extracting  $1 to $DESTDIR: (gip compressed tar)${clrend}"
240       tar x${3}f -J "$1" -C "$DESTDIR"
241       ;;
242     bz2)
243       echo -e "${clrstart}Extracting $1 to $DESTDIR: (bzip compressed tar)${clrend}"
244       tar x${3}fj "$1" -C "$DESTDIR"
245       ;;
246     zip)
247       echo -e "${clrstart}Extracting $1 to $DESTDIR: (zipp compressed file)${clrend}"
248       unzip "$1" -d "$DESTDIR"
249       ;;
250     rar)
251       echo -e "${clrstart}Extracting $1 to $DESTDIR: (rar compressed file)${clrend}"
252       unrar x "$1" "$DESTDIR"
253       ;;
254     7z)
255       echo -e  "${clrstart}Extracting $1 to $DESTDIR: (7zip compressed file)${clrend}"
256       7za e "$1" -o"$DESTDIR"
257       ;;
258     *)
259       echo -e "${clrstart}Unknown archieve format!"
260       exit 5
261       ;;
262   esac
263 }
264 #}}}
265
266
267
268 # REMIND ME, ITS IMPORTANT! {{{
269 # usage: remindme <time> <text>
270 # e.g.: remindme 10m "omg, the pizza"
271 remindme() {
272   if [[ "$#" -lt 2 ]]; then
273     echo -e "Usage: remindme [time] '[message]'"
274     echo -e "Example: remindme 50s 'check mail'"
275     echo -e "Example: remindme 10m 'go to class'"
276     #exit 0 #not enough args
277   fi
278   if [[ "$#" -gt 2 ]]; then
279     echo -e "Usage: remindme [time] '[message]'"
280     echo -e "Example: remindme 50s 'check mail'"
281     echo -e "Example: remindme 10m 'go to class'"
282     #exit 0 #more than enough args
283   fi
284   if  [[ "$#" == 2 ]]; then
285     sleep $1 && notify-send -t 15000 "$2" & echo 'Reminder set'
286   fi
287   }
288
289 #}}}
290 export PATH="$HOME/.local/bin:$PATH";
291 export PATH="$HOME/.gem/ruby/2.7.0/bin:$PATH";
292
293
294
295
296 #For arch
297 source /usr/share/bash-completion/bash_completion; #this is just for better completion
298 bind 'set show-all-if-ambiguous on';
299 bind 'TAB:menu-complete';
300
301 # HSTR configuration - add this to ~/.bashrc
302 alias hh=hstr                    # hh to be alias for hstr
303 export HSTR_CONFIG=hicolor       # get more colors
304 shopt -s histappend              # append new history items to .bash_history
305 export HISTCONTROL=ignorespace   # leading space hides commands from history
306 export HISTFILESIZE=10000        # increase history file size (default is 500)
307 export HISTSIZE=${HISTFILESIZE}  # increase history size (default is 500)
308 # ensure synchronization between bash memory and history file
309 export PROMPT_COMMAND="history -a; history -n; ${PROMPT_COMMAND}"
310 # if this is interactive shell, then bind hstr to Ctrl-r (for Vi mode check doc)
311 if [[ $- =~ .*i.* ]]; then bind '"\C-r": " hstr -- \C-j"'; fi
312 # if this is interactive shell, then bind 'kill last command' to Ctrl-x k
313 if [[ $- =~ .*i.* ]]; then bind '"\C-xk": " hstr -k \C-j"'; fi
314 # if this is an interactive shell, then bind ranger to Ctrl-f 
315 if [[ $- =~ .*i.* ]]; then bind '"\C-f": " ranger \C-j"'; fi
316
317
318
319
320
321 #############OK NEXT TIME YOU SEE THIS REMEMBER TO ORGANIZE IN MULTIPLE FILES AND CLEAN
322
323
324
325
326
327 ## HERE I'LL EXPORT SOME STUFF TO CLEAN MY HOME DIR
328 export GEM_HOME="$XDG_DATA_HOME"/gem;
329 export GEM_SPEC_CACHE="$XDG_CACHE_HOME"/gem;
330 export KDEHOME="$XDG_CONFIG_HOME"/kde;
331 export MPLAYER_HOME="$XDG_CONFIG_HOME"/mplayer;