Advertisement
Guest User

Untitled

a guest
Apr 9th, 2017
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.16 KB | None | 0 0
  1. # .bashrc
  2.  
  3. # Source global definitions
  4. if [ -f /etc/bashrc ]; then
  5. . /etc/bashrc
  6. fi
  7.  
  8. # Uncomment the following line if you don't like systemctl's auto-paging feature:
  9. # export SYSTEMD_PAGER=
  10.  
  11. # User specific aliases and functions
  12.  
  13. bold='\[\e[1m\]'
  14. reset='\[\e[0m\]'
  15. textC='\e[38;5;'
  16. backC='\e[48;5;'
  17. noColor='0m'
  18.  
  19. succBack='46m'
  20. failBack='160m'
  21.  
  22. timeText='240m'
  23. timeBack='255m'
  24. hostText='255m'
  25. hostBack='236m'
  26. pathText='16m'
  27. pathBack='32m'
  28. gitText='255m'
  29. gitBack='236m'
  30. gitSText='255m'
  31. gitSBack='236m'
  32. mainBack='8m'
  33.  
  34. botText='81m'
  35. #botStart=$'\xe2\x95\xb0\xe2\x95\xbc'
  36. #botStart=$'\xe2\x9c\x96'
  37. #botStart=$'\xe2\x9e\x9c \$'
  38. #botStart=$'\xe2\x91\x89'
  39. botStart=$'\xc2\xbb'
  40.  
  41. bulletHead=$'\xee\x82\xb0'
  42. rBulletHead=$'\xee\x82\xb2'
  43. gitSymbolChar=$'\xee\x82\xa0'
  44. #dotSym=$'\xe2\x8f\xba'
  45. dotSym=$'\xe2\x9a\xab'
  46.  
  47. get_back_color() {
  48. code=$1
  49. if [ "$code" != "0m" ]; then
  50. get_color $backC $code
  51. fi
  52. }
  53.  
  54. get_text_color() {
  55. code=$1
  56. get_color $textC $code
  57. }
  58.  
  59. get_color() {
  60. ignoreStart="\["
  61. ignoreEnd="\]"
  62. pref=$1
  63. code=$2
  64. printf "%s%s%s%s" "$ignoreStart" "$pref" "$code" "$ignoreEnd"
  65. }
  66.  
  67. print_block() {
  68. str=$3
  69.  
  70. if [ "$str" != "" ]; then
  71. textColor=`get_text_color $1`
  72. backColor=`get_back_color $2`
  73.  
  74. printf "%s%s%s%s" "$reset" "$backColor" "$textColor" "$str"
  75. fi
  76. }
  77.  
  78. get_user_size() {
  79. # +4 from the two spaces, the bullet and the "@".
  80. initSize=4
  81. user=`whoami`
  82. host=`hostname`
  83. userSize=$((${#user} + ${#host} + $initSize))
  84. echo $userSize
  85. }
  86.  
  87. get_pwd_size() {
  88. # +3 from the two spaces and the bullet.
  89. # +2 from the other two spaces and the dot.
  90. initSize=$((3 + 2))
  91. userHome=`echo $HOME`
  92.  
  93. path=`pwd`
  94. pathSize=${#path}
  95.  
  96. if [ "$path" == "$userHome" ]; then
  97. # 1 from the "~" that will be left
  98. pathSize=1
  99. elif [ ! -z "`echo $path | grep $userHome`" ]; then
  100. # +2 from the "~" that will be added
  101. pathSize=$((${#path} - ${#userHome} + 1))
  102. fi
  103.  
  104. pathSize=$(($pathSize + $initSize))
  105. echo $pathSize
  106. }
  107.  
  108. get_git_size() {
  109. # +3 from the two spaces and the bullet.
  110. # +2 from the other two spaces and the dot.
  111. initSize=$((3 + 2))
  112.  
  113. gitInfo=$1
  114. gitSize=0
  115.  
  116. if [ ! -z "$gitInfo" ]; then
  117. ### +1 from symbol.
  118. gitSize=$((${#gitInfo} + $initSize + 1))
  119. fi
  120.  
  121. echo $gitSize
  122. }
  123.  
  124. get_time_size() {
  125. dotSize=0
  126. [ ! -z "$2" ]; dotSize=$2
  127.  
  128. # +3 from the two spaces and the bullet.
  129. # + the size in
  130. initSize=$((3 + $dotSize))
  131.  
  132. timeInfo=$1
  133. timeSize=0
  134.  
  135. if [ ! -z $timeInfo ]; then
  136. timeSize=$((${#timeInfo} + $initSize))
  137. fi
  138.  
  139. echo $timeSize
  140. }
  141.  
  142. get_column_offset() {
  143. used=$1
  144.  
  145. colNum=$COLUMNS
  146. while [ $colNum -lt $used ]; do
  147. colNum=$(($colNum + $COLUMNS))
  148. done
  149.  
  150. offset=$(($colNum - $used))
  151. echo $offset
  152. }
  153.  
  154. show_prompt() {
  155. if [ $? -eq 0 ]; then
  156. statusBack=$succBack
  157. else
  158. statusBack=$failBack
  159. fi
  160. statusBlock=`print_block $hostBack $statusBack $rBulletHead`
  161.  
  162. hostBlock=`print_block $hostText $hostBack " \\u@\\h "`
  163. hostBullet=`print_block $hostBack $pathBack $bulletHead`
  164. pathBlock=`print_block $pathText $pathBack " \\w "`
  165. pathBullet=`print_block $pathBack $mainBack $bulletHead`
  166. leftDot=`print_block $noColor $pathBack $dotSym`
  167.  
  168. gitBlock=""
  169. gitBullet=""
  170. gitSymbol=""
  171.  
  172. timeInfo=`date +%T`
  173. timeBlock=`print_block $timeText $timeBack " $timeInfo "`
  174. timeBullet=`print_block $timeBack $mainBack $rBulletHead`
  175. rightDot=`print_block $noColor $timeBack $dotSym`
  176.  
  177. gitInfo=$(__git_ps1)
  178. if [ ! -z "$gitInfo" ]; then
  179. ### Used when git is on the left
  180. # pathBullet=`print_block $pathBack $gitBack $bulletHead`
  181. ### Used when git is on the right
  182. timeBullet=`print_block $timeBack $gitBack $rBulletHead`
  183. gitBlock=`print_block $gitText $gitBack "$gitInfo "`
  184. gitBullet=`print_block $gitBack $mainBack $rBulletHead`
  185. gitSymbol=`print_block $gitSText $gitSBack "$gitSymbolChar "`
  186. rightDot=`print_block $noColor $gitBack $dotSym`
  187. fi
  188.  
  189. termName="\[\e]0;\u@\h:\w\a\]"
  190.  
  191. host="$hostBlock$hostBullet"
  192. path="$pathBlock$leftDot $pathBullet"
  193. ### Used when git is on the left
  194. # git="$gitBlock$gitBullet"
  195. ### Used when git is on the right
  196. git="$gitBullet$gitBlock$gitSymbol"
  197. time="$timeBullet$timeBlock"
  198. status="$statusBlock"
  199.  
  200. if [ -z "$gitInfo" ]; then
  201. time="$timeBullet$rightDot $timeBlock"
  202. timeSize=2
  203. else
  204. git="$gitBullet$rightDot $gitBlock$gitSymbol"
  205. timeSize=0
  206. fi
  207.  
  208. ### +1 from status.
  209. usedColumns=$((1 + `get_user_size` + `get_pwd_size` + `get_git_size "$gitInfo"` + `get_time_size $timeInfo $timeSize`))
  210. offset=`get_column_offset $usedColumns`
  211.  
  212. #bottom=`print_block $botText $noColor $botStart`
  213. bottom=`print_block $botText $noColor "-=-"`
  214.  
  215. ### Used when git is on the left
  216. # PS1="$termName`printf "%s%s%s%s%${offset}s%s" "$status" "$host" "$path" "$git" "" "$time"`$reset\n $bottom$reset "
  217. ### Used when git is on the right
  218. PS1="$termName`printf "%s%s%s%${offset}s%s%s%s" "$status" "$host" "$path" "" "$git" "$time"`$reset\n$bold$bottom$reset "
  219.  
  220. # PS1="\[\e]0;\u@\h:\w\a\]$bold$whiteBox $thisTime $whiteToGreen$bulletHead$greenBox \u@\h $greenToBlue$bulletHead $blueBox\w $blueTo$bulletHead$redBox$gitInfo$gitBulletHead$reset\n$reset$bold$white$bot_start$reset "
  221. }
  222.  
  223. PROMPT_COMMAND=show_prompt
  224.  
  225. bashComp="/usr/share/bash-completion/bash_completion"
  226. [ -f $bashComp ]; . $bashComp
  227.  
  228. gitPrompt="/etc/bash_completion.d/git-prompt"
  229. [ -f $gitPrompt ]; . $gitPrompt
  230.  
  231. # Sourcing completions
  232. compFolder="/usr/share/bash-completion/completions"
  233. scripts=( "git" "apt" "apt-get" "apt-cache" "find" "cmake" "groupadd" "groupdel" \
  234. "modprobe" "mount" "gsettings" "ip" "java" "kill" "useradd" "userdel" "update-alternatives" )
  235.  
  236. for script in ${scripts[@]}; do
  237. [ -f $compFolder/$script ]; . $compFolder/$script
  238. done
  239.  
  240. # IBus utils
  241. export GTK_IM_MODULE=ibus
  242. export XMODIFIERS=@im=ibus
  243. export QT_IM_MODULE=ibus
  244.  
  245. # Ssh anoyance
  246. export SSH_ASKPASS=
  247.  
  248. # Default aliases
  249. alias ls='ls --color'
  250. alias grep='grep --color'
  251. alias tmux='TERM=screen-256color-bce tmux'
  252.  
  253. # PATH configuration
  254. # export PATH=$PATH:/usr/local/cuda/bin
  255.  
  256. screenfetch
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement