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.

159 lines
3.9 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|9.*)
  34. backports_list="/etc/apt/sources.list.d/backports.list"
  35. protect_pre_install /etc/apt/sources.list.d/backports.list
  36. echo "deb http://archive.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. ;;
  42. esac
  43. ;;
  44. esac
  45. apt-get install fzf </dev/null
  46. fi
  47. if ! type -p fd-find; then
  48. if apt-get install fd-find </dev/null; then
  49. ln -sf "$(which fdfind)" /usr/local/bin/fd
  50. else
  51. wget https://github.com/sharkdp/fd/releases/download/v8.2.1/fd_8.2.1_amd64.deb -O /tmp/fd.deb
  52. dpkg -i /tmp/fd.deb
  53. fi
  54. fi
  55. if ! [ -e "/usr/share/doc/fzf/examples/key-bindings.bash.orig" ]; then
  56. ## Use C-f instead of C-t for file insertion
  57. sed -r -i.orig 's/C-t/C-f/g' /usr/share/doc/fzf/examples/key-bindings.bash
  58. fi
  59. cat <<EOF >> /root/.bashrc
  60. ## History management
  61. export HISTCONTROL=ignoreboth
  62. export HISTSIZE=500000
  63. export HISTIGNORE="&:[bf]g:exit:ls:history"
  64. export HISTFILESIZE=
  65. export HISTTIMEFORMAT="%Y-%m-%d %T "
  66. shopt -s histappend
  67. ## Prompt easy management
  68. prompt() {
  69. prompt_name="prompt.\$1.rc"
  70. for i in /etc/prompt ~/.prompt; do
  71. [ -f "\$i/\$prompt_name" ] &&
  72. . "\$i/\$prompt_name"
  73. done
  74. }
  75. ## Git log command
  76. function glog() {
  77. git log --graph --pretty=tformat:%C\(yellow\ normal\)%h%Creset\ %C\(blue\ normal\)%an%Creset\ %s\ %Cgreen%d%Creset -n 20 "\$@"
  78. }
  79. prompt 1
  80. PROMPT_COMMAND='history -a' ## after prompt setting as it resets it
  81. ##
  82. ## fzf (apt-get install fzf) and fd (apt-get install fd-find)
  83. ##
  84. if [ -e /usr/share/doc/fzf/examples/key-bindings.bash ]; then
  85. . /usr/share/doc/fzf/examples/key-bindings.bash
  86. fi
  87. if [ -e /usr/share/doc/fzf/examples/completion.bash ]; then
  88. . /usr/share/doc/fzf/examples/completion.bash
  89. fi
  90. #export FZF_DEFAULT_OPTS="--color 'fg:#bbccdd,fg+:#ddeeff,bg:#111820,preview-bg:#223344,border:#778899'"
  91. export FZF_DEFAULT_COMMAND='fd --type f --hidden --follow --exclude .git'
  92. export FZF_CTRL_T_COMMAND="\$FZF_DEFAULT_COMMAND"
  93. EOF
  94. protect_pre_install "/root/.bash_profile"
  95. cat <<EOF >> /root/.bash_profile
  96. ## XXXvlab:
  97. ## http://stackoverflow.com/questions/9652126/bashrc-profile-is-not-loaded-on-new-tmux-session-or-window-why
  98. ## Including ``.bashrc`` if it exists (tmux don't load bashrc, and bashrc
  99. ## don't load profile... so not recursive call)
  100. if [ -f ~/.bashrc ]; then
  101. . ~/.bashrc
  102. fi
  103. EOF
  104. protect_pre_install /root/.vimrc
  105. cat <<EOF >> /root/.vimrc
  106. syntax on
  107. filetype plugin indent on
  108. "Get the 2-space YAML as the default when hit carriage return after the colon
  109. autocmd FileType yaml,yml setlocal ts=2 sts=2 sw=2 expandtab indentkeys=
  110. set is hlsearch ai ic scs
  111. nnoremap <esc><esc> :nohls<cr>
  112. EOF