Pārlūkot izejas kodu

Add ruby environment, clang-format injectors, source-code locator

Sam Jaffe 2 gadi atpakaļ
vecāks
revīzija
d9218c74bb
8 mainītis faili ar 169 papildinājumiem un 1 dzēšanām
  1. 3 0
      bashrc
  2. 11 0
      profile-dev
  3. 11 0
      profile-git
  4. 1 1
      profile-osx
  5. 1 0
      profile-util
  6. 29 0
      resources/clang-format.hook
  7. 108 0
      resources/clang-format.template
  8. 5 0
      resources/pre-commit-all.hook

+ 3 - 0
bashrc

@@ -7,3 +7,6 @@ if [[ -f ${HOME}/.profile-local ]]; then . ${HOME}/.profile-local; fi
 
 
 [ -f ~/.fzf.bash ] && source ~/.fzf.bash
+
+# Add RVM to PATH for scripting. Make sure this is the last PATH variable change.
+export PATH="$PATH:$HOME/.rvm/bin"

+ 11 - 0
profile-dev

@@ -0,0 +1,11 @@
+print_ext_c() { echo "c h"; }
+print_ext_cxx() { echo "cxx cpp cc h hh hpp ipp tpp"; }
+
+locate_source_files() {
+  local sources=($(eval print_ext_${1:1}))
+  eval find "${@:2}" -type f \
+    \\\( \
+      -name '__blank__' \
+      $(printf " -o -name '*.%s'" "${sources[@]}") \
+    \\\)
+}

+ 11 - 0
profile-git

@@ -10,6 +10,17 @@ git-ignore() {
   wget -qO- "${site}/${1}.gitignore" >> "${ignore_file}"
 }
 
+git-inject-clang-format() {
+  local fromdir todir
+  fromdir=${HOME}/.dotfiles/resources
+  todir=.git/hooks
+  mkdir -p "${todir}/pre-commit.d"
+  git config hooks.clangformat.style file
+  cp ${fromdir}/clang-format.template ./.clang-format
+  cp ${fromdir}/pre-commit-all.hook ${todir}/pre-commit
+  cp ${fromdir}/clang-format.hook ${todir}/pre-commit.d/clang-format
+}
+
 git-create() {
   mkcd "${1}"; shift
   git init

+ 1 - 1
profile-osx

@@ -1,4 +1,4 @@
-alias list="ls -lFhG"
+alias list="ls -lFhG --color"
 
 readlink() {
   if [[ "$1" == "-f" ]]; then

+ 1 - 0
profile-util

@@ -198,6 +198,7 @@ else
   . ${HOME}/.profile-linux
 fi
 
+. ${HOME}/.profile-dev
 has git && . ${HOME}/.profile-git || true
 has p4 && . ${HOME}/.profile-p4 || true
 

+ 29 - 0
resources/clang-format.hook

@@ -0,0 +1,29 @@
+#!/bin/bash
+
+PATH="${PATH}:/opt/local/bin"; export PATH
+STYLE=$(git config --get hooks.clangformat.style)
+if [ -n "${STYLE}" ] ; then
+  STYLEARG="-style=${STYLE}"
+else
+  STYLEARG=""
+fi
+
+format_file() {
+  file="${1}"
+  if [ -f $file ]; then
+    clang-format -i ${STYLEARG} ${1}
+    git add ${1}
+  fi
+}
+
+case "${1}" in
+  --about )
+    echo "Runs clang-format on source files"
+    ;;
+  * )
+    for file in `git diff-index --cached --name-only HEAD | grep -iE '\.(cpp|cxx|cc|h|hh|hpp|inl|tpp)$' ` ; do
+      format_file "${file}"
+    done
+    ;;
+esac
+

+ 108 - 0
resources/clang-format.template

@@ -0,0 +1,108 @@
+---
+Language:        Cpp
+# BasedOnStyle:  LLVM
+AccessModifierOffset: -2
+AlignAfterOpenBracket: Align
+AlignConsecutiveAssignments: false
+AlignConsecutiveDeclarations: false
+AlignEscapedNewlines: Right
+AlignOperands:   true
+AlignTrailingComments: true
+AllowAllParametersOfDeclarationOnNextLine: true
+AllowShortBlocksOnASingleLine: true
+AllowShortCaseLabelsOnASingleLine: false
+AllowShortFunctionsOnASingleLine: All
+AllowShortIfStatementsOnASingleLine: true
+AllowShortLoopsOnASingleLine: false
+AlwaysBreakAfterDefinitionReturnType: None
+AlwaysBreakAfterReturnType: None
+AlwaysBreakBeforeMultilineStrings: false
+AlwaysBreakTemplateDeclarations: false
+BinPackArguments: true
+BinPackParameters: true
+BraceWrapping:   
+  AfterClass:      false
+  AfterControlStatement: false
+  AfterEnum:       false
+  AfterFunction:   false
+  AfterNamespace:  false
+  AfterObjCDeclaration: false
+  AfterStruct:     false
+  AfterUnion:      false
+  BeforeCatch:     false
+  BeforeElse:      false
+  IndentBraces:    false
+  SplitEmptyFunction: true
+  SplitEmptyRecord: true
+  SplitEmptyNamespace: true
+BreakBeforeBinaryOperators: None
+BreakBeforeBraces: Attach
+BreakBeforeInheritanceComma: false
+BreakBeforeTernaryOperators: true
+BreakConstructorInitializersBeforeComma: false
+BreakConstructorInitializers: BeforeColon
+BreakAfterJavaFieldAnnotations: false
+BreakStringLiterals: true
+ColumnLimit:     80
+CommentPragmas:  '^ IWYU pragma:'
+CompactNamespaces: true
+ConstructorInitializerAllOnOneLineOrOnePerLine: false
+ConstructorInitializerIndentWidth: 4
+ContinuationIndentWidth: 4
+Cpp11BracedListStyle: true
+DerivePointerAlignment: false
+DisableFormat:   false
+ExperimentalAutoDetectBinPacking: false
+FixNamespaceComments: false
+ForEachMacros:   
+  - foreach
+  - Q_FOREACH
+  - BOOST_FOREACH
+IncludeCategories: 
+  - Regex:           '^"(llvm|llvm-c|clang|clang-c)/'
+    Priority:        2
+  - Regex:           '^(<|"(gtest|gmock|isl|json)/)'
+    Priority:        3
+  - Regex:           '.*'
+    Priority:        1
+IncludeIsMainRegex: '(Test)?$'
+IndentCaseLabels: false
+IndentWidth:     2
+IndentWrappedFunctionNames: false
+JavaScriptQuotes: Leave
+JavaScriptWrapImports: true
+KeepEmptyLinesAtTheStartOfBlocks: true
+MacroBlockBegin: ''
+MacroBlockEnd:   ''
+MaxEmptyLinesToKeep: 1
+NamespaceIndentation: None
+ObjCBlockIndentWidth: 2
+ObjCSpaceAfterProperty: false
+ObjCSpaceBeforeProtocolList: true
+PenaltyBreakAssignment: 2
+PenaltyBreakBeforeFirstCallParameter: 19
+PenaltyBreakComment: 300
+PenaltyBreakFirstLessLess: 120
+PenaltyBreakString: 1000
+PenaltyExcessCharacter: 1000000
+PenaltyReturnTypeOnItsOwnLine: 60
+PointerAlignment: Middle
+ReflowComments:  true
+SortIncludes:    true
+SortUsingDeclarations: true
+SpaceAfterCStyleCast: false
+SpaceAfterTemplateKeyword: true
+SpaceBeforeAssignmentOperators: true
+SpaceBeforeParens: ControlStatements
+SpaceInEmptyParentheses: false
+SpacesBeforeTrailingComments: 1
+SpacesInAngles:  false
+SpacesInContainerLiterals: true
+SpacesInCStyleCastParentheses: false
+SpacesInParentheses: false
+SpacesInSquareBrackets: false
+Standard:        Cpp11
+TabWidth:        8
+UseTab:          Never
+...
+

+ 5 - 0
resources/pre-commit-all.hook

@@ -0,0 +1,5 @@
+#!/bin/bash
+
+for file in .git/hooks/pre-commit.d/*; do
+  bash "${file}" "${1}"
+done