You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

132 lines
3.4 KiB

  1. #!/bin/bash
  2. ## Requires kal-script
  3. ##
  4. ## More shell configurations (prompt, functions)
  5. ##
  6. mkdir -p /etc/prompt
  7. cat <<EOF > /etc/prompt/prompt.1.rc
  8. PROMPT_COMMAND=""
  9. parse_git_branch() {
  10. ref=\$(git symbolic-ref HEAD 2> /dev/null) || return
  11. echo -en ' (\033[0;32m'\${ref#refs/heads/}'\033[0m)'
  12. }
  13. export PS1="\[\033[0;37m\][\[\033[1;30m\]\u\[\033[0;37m\]@\[\033[1;30m\]\H\[\033[0;37m\]]-[\[\033[1;34m\]\w\[\033[0;37m\]]\\\$(parse_git_branch)\n\[\033[1;37m\]\\$ \[\033[0;37m\]"
  14. EOF
  15. if [ -f /root/.bashrc.pre-install ]; then
  16. cp /root/.bashrc.pre-install /root/.bashrc
  17. else
  18. cp /root/.bashrc /root/.bashrc.pre-install
  19. fi
  20. if ! type -p fzf; then
  21. ## Required to get fzf
  22. case $(lsb_release -is) in
  23. Debian)
  24. case $(lsb_release -rs) in
  25. 9)
  26. backports_list="/etc/apt/sources.list.d/backports.list"
  27. if ! [ -e "$backports_list" ]; then
  28. echo "deb http://ftp.debian.org/debian stretch-backports main" > \
  29. "$backports_list"
  30. ## Update only this repo:
  31. apt-get update -o Dir::Etc::sourcelist="sources.list.d/backports.list" \
  32. -o Dir::Etc::sourceparts="-" -o APT::Get::List-Cleanup="0"
  33. fi
  34. ;;
  35. esac
  36. ;;
  37. esac
  38. apt-get install fzf </dev/null
  39. fi
  40. if ! type -p fd-find; then
  41. if apt-get install fd-find </dev/null; then
  42. ln -sf "$(which fdfind)" /usr/local/bin/fd
  43. else
  44. wget https://github.com/sharkdp/fd/releases/download/v8.2.1/fd_8.2.1_amd64.deb -O /tmp/fd.deb
  45. dpkg -i /tmp/fd.deb
  46. fi
  47. fi
  48. if ! [ -e "/usr/share/doc/fzf/examples/key-bindings.bash.orig" ]; then
  49. ## Use C-f instead of C-t for file insertion
  50. sed -r -i.orig 's/C-t/C-f/g' /usr/share/doc/fzf/examples/key-bindings.bash
  51. fi
  52. cat <<EOF >> /root/.bashrc
  53. ## History management
  54. export HISTCONTROL=ignoreboth
  55. export HISTSIZE=500000
  56. export HISTIGNORE="&:[bf]g:exit:ls:history"
  57. export HISTFILESIZE=
  58. export HISTTIMEFORMAT="%Y-%m-%d %T "
  59. shopt -s histappend
  60. ## Prompt easy management
  61. prompt() {
  62. prompt_name="prompt.\$1.rc"
  63. for i in /etc/prompt ~/.prompt; do
  64. [ -f "\$i/\$prompt_name" ] &&
  65. . "\$i/\$prompt_name"
  66. done
  67. }
  68. ## Git log command
  69. function glog() {
  70. git log --graph --pretty=tformat:%C\(yellow\ normal\)%h%Creset\ %C\(blue\ normal\)%an%Creset\ %s\ %Cgreen%d%Creset -n 20 "\$@"
  71. }
  72. prompt 1
  73. PROMPT_COMMAND='history -a' ## after prompt setting as it resets it
  74. ##
  75. ## fzf (apt-get install fzf) and fd (apt-get install fd-find)
  76. ##
  77. if [ -e /usr/share/doc/fzf/examples/key-bindings.bash ]; then
  78. . /usr/share/doc/fzf/examples/key-bindings.bash
  79. fi
  80. if [ -e /usr/share/doc/fzf/examples/completion.bash ]; then
  81. . /usr/share/doc/fzf/examples/completion.bash
  82. fi
  83. #export FZF_DEFAULT_OPTS="--color 'fg:#bbccdd,fg+:#ddeeff,bg:#111820,preview-bg:#223344,border:#778899'"
  84. export FZF_DEFAULT_COMMAND='fd --type f --hidden --follow --exclude .git'
  85. export FZF_CTRL_T_COMMAND="$FZF_DEFAULT_COMMAND"
  86. EOF
  87. cat <<EOF >> /root/.bash_profile
  88. ## XXXvlab:
  89. ## http://stackoverflow.com/questions/9652126/bashrc-profile-is-not-loaded-on-new-tmux-session-or-window-why
  90. ## Including ``.bashrc`` if it exists (tmux don't load bashrc, and bashrc
  91. ## don't load profile... so not recursive call)
  92. if [ -f ~/.bashrc ]; then
  93. . ~/.bashrc
  94. fi
  95. EOF