bastien 1 tháng trước cách đây
mục cha
commit
741612366a
3 tập tin đã thay đổi với 253 bổ sung0 xóa
  1. 107 0
      bash/bashrc-linux
  2. 71 0
      bash/bashrc-osx
  3. 75 0
      bash/bashrc-server

+ 107 - 0
bash/bashrc-linux

@@ -0,0 +1,107 @@
+## Enable color support of ls and also add handy aliases
+# Some colors
+alias ls='ls --color=auto'
+alias grep='grep --color=auto'
+
+## Some export
+# colored GCC warnings and errors
+export GCC_COLORS='error=01;31:warning=01;35:note=01;36:caret=01;32:locus=01:quote=01'
+
+# Set history size to unlimited
+if [[ $EUID == 0 ]] ; then
+	export HISTSIZE=0
+	export HISTFILESIZE=0
+else
+	export HISTSIZE=-1
+	export HISTFILESIZE=-1
+fi
+
+#export LANG=en_US.UTF-8
+
+
+# Used for vim header
+export VIUSER=bchanot
+export VIMAIL=bchanot@gmail.fr
+
+## Activate and custom bash completion
+#bind 'TAB:menu-complete'
+#bind 'set show-all-if-ambiguous on'
+
+## Setting prompt style
+# Get current branch in git repo
+function parse_git_branch() {
+	BRANCH=`git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/'`
+	if [ ! "${BRANCH}" == "" ]
+		then
+			STAT=`parse_git_dirty`
+			echo " [${BRANCH}${STAT}]"
+		else
+			echo ""
+	fi
+}
+function timer_now {
+    date +%s%N
+}
+
+function timer_start {
+    timer_start=${timer_start:-$(timer_now)}
+}
+
+function timer_stop {
+    local delta_us=$((($(timer_now) - $timer_start) / 1000))
+    local us=$((delta_us % 1000))
+    local ms=$(((delta_us / 1000) % 1000))
+    local s=$(((delta_us / 1000000) % 60))
+    local m=$(((delta_us / 60000000) % 60))
+    local h=$((delta_us / 3600000000))
+    # Goal: always show around 3 digits of accuracy
+    if ((h > 0)); then timer_show=${h}h${m}m
+    elif ((m > 0)); then timer_show=${m}m${s}s
+    elif ((s >= 10)); then timer_show=${s}.$((ms / 100))s
+    elif ((s > 0)); then timer_show=${s}.$(printf %03d $ms)s
+    elif ((ms >= 100)); then timer_show=${ms}ms
+    elif ((ms > 0)); then timer_show=${ms}.$((us / 100))ms
+    else timer_show=${us}us
+    fi
+    unset timer_start
+}
+# get current status of git repo
+function parse_git_dirty {
+	status=`git status 2>&1 | tee`
+	dirty=`echo -n "${status}" 2> /dev/null | grep "modified:" &> /dev/null; echo "$?"`
+	untracked=`echo -n "${status}" 2> /dev/null | grep "Untracked files" &> /dev/null; echo "$?"`
+	ahead=`echo -n "${status}" 2> /dev/null | grep "Your branch is ahead of" &> /dev/null; echo "$?"`
+	newfile=`echo -n "${status}" 2> /dev/null | grep "new file:" &> /dev/null; echo "$?"`
+	renamed=`echo -n "${status}" 2> /dev/null | grep "renamed:" &> /dev/null; echo "$?"`
+	deleted=`echo -n "${status}" 2> /dev/null | grep "deleted:" &> /dev/null; echo "$?"`
+	bits=''
+	if [ "${renamed}" == "0" ] || [ "${newfile}" == "0" ] || [ "${untracked}" == "0" ] || [ "${dirty}" == "0" ]; then
+		bits="+${bits}"
+	fi
+	if [ "${ahead}" == "0" ]; then
+		bits="*${bits}"
+	fi
+	if [ "${deleted}" == "0" ]; then
+		bits="-${bits}"
+	fi
+	if [ ! "${bits}" == "" ]
+		then
+			echo " ${bits}"
+		else
+			echo ""
+	fi
+}
+
+function set_prompt {
+	timer_stop
+
+	if [[ $EUID == 0 ]] ; then
+		export PS1='`if [ $? = 0 ]; then echo "\[\033[01;36m\]✔"; else echo "\[\033[01;31m\]✘"; fi` ($timer_show) \[\033[01;31m\]\u [\[\033[00;0m\] \w \[\033[01;31m\]]\[\033[01;34m\]$(parse_git_branch " %s") \[\033[00;00m\]> '
+	else
+		export PS1='`if [ $? = 0 ]; then echo "\[\033[01;36m\]✔"; else echo "\[\033[01;31m\]✘"; fi` ($timer_show) \[\033[01;32m\]\u [\[\033[00;0m\] \w \[\033[01;32m\]]\[\033[01;34m\]$(parse_git_branch " %s") \[\033[00;00m\]> '
+	fi
+}
+
+trap 'timer_start' DEBUG
+PROMPT_COMMAND='set_prompt'
+## Lancement des commandes au demarrages

+ 71 - 0
bash/bashrc-osx

@@ -0,0 +1,71 @@
+## Enable color support of ls and also add handy aliases
+# Some colors
+alias ls='ls -G'
+alias grep='grep --color=auto'
+
+# Some utils aliases
+alias ll='ls -l'
+alias la='ls -A'
+alias rmrf='rm -rf'
+alias gcl='git clone'
+alias vim='vim -p'
+
+# Aliases for executing ~/.script scripts
+alias gitan='sh ~/.script/gitan.sh'
+alias clean='sh ~/.script/clean.sh'
+
+## Some export
+# colored GCC warnings and errors
+export GCC_COLORS='error=01;31:warning=01;35:note=01;36:caret=01;32:locus=01:quote=01'
+
+# Used for vim header
+export VIUSER=xuser
+export VIMAIL=xuser@student.42.fr
+
+## Activate and custom bash completion
+#bind 'TAB:menu-complete'
+#bind 'set show-all-if-ambiguous on'
+
+## Setting prompt style
+# Get current branch in git repo
+function parse_git_branch() {
+	BRANCH=`git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/'`
+	if [ ! "${BRANCH}" == "" ]
+		then
+			STAT=`parse_git_dirty`
+			echo " [${BRANCH}${STAT}]"
+		else
+			echo ""
+	fi
+}
+
+# get current status of git repo
+function parse_git_dirty {
+	status=`git status 2>&1 | tee`
+	dirty=`echo -n "${status}" 2> /dev/null | grep "modified:" &> /dev/null; echo "$?"`
+	untracked=`echo -n "${status}" 2> /dev/null | grep "Untracked files" &> /dev/null; echo "$?"`
+	ahead=`echo -n "${status}" 2> /dev/null | grep "Your branch is ahead of" &> /dev/null; echo "$?"`
+	newfile=`echo -n "${status}" 2> /dev/null | grep "new file:" &> /dev/null; echo "$?"`
+	renamed=`echo -n "${status}" 2> /dev/null | grep "renamed:" &> /dev/null; echo "$?"`
+	deleted=`echo -n "${status}" 2> /dev/null | grep "deleted:" &> /dev/null; echo "$?"`
+	bits=''
+	if [ "${renamed}" == "0" ] || [ "${newfile}" == "0" ] || [ "${untracked}" == "0" ] || [ "${dirty}" == "0" ]; then
+		bits="+${bits}"
+	fi
+	if [ "${ahead}" == "0" ]; then
+		bits="*${bits}"
+	fi
+	if [ "${deleted}" == "0" ]; then
+		bits="-${bits}"
+	fi
+	if [ ! "${bits}" == "" ]
+		then
+			echo " ${bits}"
+		else
+			echo ""
+	fi
+}
+
+export PS1='`if [ $? = 0 ]; then echo "\[\033[01;36m\]✔"; else echo "\[\033[01;31m\]✘"; fi` \[\033[32m\]\w\[\033[34m\]$(parse_git_branch " %s") \[\033[0m\]>\[\033[00m\] '
+
+## Lancement des commandes au demarrages

+ 75 - 0
bash/bashrc-server

@@ -0,0 +1,75 @@
+## Enable color support of ls and also add handy aliases
+# Some colors
+alias ls='ls --color=auto'
+alias grep='grep --color=auto'
+
+# Some utils aliases
+alias ll='ls -l'
+alias la='ls -A'
+alias rmrf='rm -rf'
+alias gcl='git clone'
+
+# Aliases for executing ~/.script scripts
+alias gitan='sh ~/.script/gitan.sh'
+alias clean='sh ~/.script/clean.sh'
+
+## Some export
+# colored GCC warnings and errors
+export GCC_COLORS='error=01;31:warning=01;35:note=01;36:caret=01;32:locus=01:quote=01'
+
+# Set history size to unlimited
+export HISTSIZE=-1
+export HISTFILESIZE=-1
+
+# For header vim
+#export VIUSER=xuser
+#export VIMAIL=xuser@xdomain.tld
+
+## Activate and custom bash completion
+#bind 'TAB:menu-complete'
+#bind 'set show-all-if-ambiguous on'
+
+## Setting prompt style
+# Get current branch in git repo
+function parse_git_branch() {
+	BRANCH=`git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/'`
+	if [ ! "${BRANCH}" == "" ]
+		then
+			STAT=`parse_git_dirty`
+			echo " [${BRANCH}${STAT}]"
+		else
+			echo ""
+	fi
+}
+
+# get current status of git repo
+function parse_git_dirty {
+	status=`git status 2>&1 | tee`
+	dirty=`echo -n "${status}" 2> /dev/null | grep "modified:" &> /dev/null; echo "$?"`
+	untracked=`echo -n "${status}" 2> /dev/null | grep "Untracked files" &> /dev/null; echo "$?"`
+	ahead=`echo -n "${status}" 2> /dev/null | grep "Your branch is ahead of" &> /dev/null; echo "$?"`
+	newfile=`echo -n "${status}" 2> /dev/null | grep "new file:" &> /dev/null; echo "$?"`
+	renamed=`echo -n "${status}" 2> /dev/null | grep "renamed:" &> /dev/null; echo "$?"`
+	deleted=`echo -n "${status}" 2> /dev/null | grep "deleted:" &> /dev/null; echo "$?"`
+	bits=''
+	if [ "${renamed}" == "0" ] || [ "${newfile}" == "0" ] || [ "${untracked}" == "0" ] || [ "${dirty}" == "0" ]; then
+		bits="+${bits}"
+	fi
+	if [ "${ahead}" == "0" ]; then
+		bits="*${bits}"
+	fi
+	if [ "${deleted}" == "0" ]; then
+		bits="-${bits}"
+	fi
+	if [ ! "${bits}" == "" ]
+		then
+			echo " ${bits}"
+		else
+			echo ""
+	fi
+}
+
+IP_LOC=`ip -4 -o addr show | grep "eth0" | cut -f7 -d' ' | cut -f1 -d'/'`
+IP_PUB=`wget -q -O - checkip.dyndns.org|sed -e 's/.*Current IP Address: //' -e 's/<.*$//'`
+
+export PS1='` if [ $? = 0 ]; then echo "\[\033[01;32m\]✔"; else echo "\[\033[01;31m\]✘"; fi` \[\033[36m\]\u\[\033[00m\]@\[\033[01;36m\]$IP_LOC\[\033[32m\] \w\[\033[34m\]$(parse_git_branch " %s") \[\033[0m\]>\[\033[00m\] '