fork 0k-charms
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.

144 lines
3.6 KiB

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