diff options
author | Simon Rettberg | 2013-12-16 20:26:12 +0100 |
---|---|---|
committer | Simon Rettberg | 2013-12-16 20:26:12 +0100 |
commit | 498b199fa5240c8aa27a2704708d1eb098bf3105 (patch) | |
tree | 5c4489b6a8294c2f8abb18e4a0723d787969503e /doc/coding | |
parent | [pam-offenburg] Adapt to new pam_script_* format (diff) | |
download | tm-scripts-498b199fa5240c8aa27a2704708d1eb098bf3105.tar.gz tm-scripts-498b199fa5240c8aa27a2704708d1eb098bf3105.tar.xz tm-scripts-498b199fa5240c8aa27a2704708d1eb098bf3105.zip |
Some docs about coding
Diffstat (limited to 'doc/coding')
-rw-r--r-- | doc/coding/coding-style | 27 | ||||
-rw-r--r-- | doc/coding/shell-scripts | 32 | ||||
-rw-r--r-- | doc/coding/vim-coloring | 20 |
3 files changed, 79 insertions, 0 deletions
diff --git a/doc/coding/coding-style b/doc/coding/coding-style new file mode 100644 index 00000000..b3658ef8 --- /dev/null +++ b/doc/coding/coding-style @@ -0,0 +1,27 @@ +Some guidelines + +-- 1. Leading Tabs, no spaces. +.vimrc: +set noexpandtab +set tabstop=<spaces to display per tab> +set autoindent + +If you want to see leading/trailing spaces: +highlight ExtraWhitespace ctermbg=red guibg=red +match ExtraWhitespace /^\t*\zs \+\|\s\+\%#\@<!$/ + + +-- 2. ALL_CAPS_VARIABLE_NAMES +Variable names should be in caps. You can use lowercase +in for statements, like "for i in $SOME_STUFF; do" +Some old scripts haven't been updated yet.... + + +-- 3. "do", "then" ... on the same line +for i in x; do +if [ xyz ]; then + + +-- 4. + + diff --git a/doc/coding/shell-scripts b/doc/coding/shell-scripts new file mode 100644 index 00000000..14e69c6e --- /dev/null +++ b/doc/coding/shell-scripts @@ -0,0 +1,32 @@ +Since this framework is supposed to work on several +distributions, we cannot rely on a certain shell +always being available in one specific version. +Care should be taken which shebang a script uses. +As the only shell we know for sure will be there +is the ash that comes with busybox it is advised +that you write scripts that are compatible to ash +whenever possible. +So pretty much all scripts should start with +#!/bin/ash +It is guaranteed by the framework that /bin/ash +will link to mltk's busybox binary. + +In case you have a fancy script that uses some bash +features it is reasonably safe to assume that the +distribution in use supplies a halfway up to date +bash version, so if you don't use any bleeding edge +features you might use +#!/bin/bash +for that script. Keep in mind that bash takes a +little while to start up (even if loaded from ram), +so don't use it if you don't have to. + +You should NEVER USE /bin/sh as the shebang, as the +results are undefined. /bin/sh links to something +distribution specific, so just because it works on +one system doesn't mean it works on another +(debian/ubuntu's dash is great in breaking bash +scripts for example). +We do not modify /bin/sh so we don't accidentally +break any scripts that come with the distro (stage4). + diff --git a/doc/coding/vim-coloring b/doc/coding/vim-coloring new file mode 100644 index 00000000..693c22ee --- /dev/null +++ b/doc/coding/vim-coloring @@ -0,0 +1,20 @@ +In case you want to have proper syntax highlighting: + + +For mltk module files, in .vimrc: +au BufRead,BufNewFile *.build set filetype=sh +au BufRead,BufNewFile *.conf set filetype=sh +au BufRead,BufNewFile *.conf.* set filetype=sh +au BufRead,BufNewFile *.inc set filetype=sh +au BufRead,BufNewFile *.include set filetype=sh + + +For #!/bin/ash in scripts, create .vim/scripts.vim: +if did_filetype() + finish +endif + +if getline(1) =~# '^#!.*/ash' + setf sh +endif + |