Permalink
Browse files

add: file shebang is

  • Loading branch information...
mpapis committed Aug 27, 2012
1 parent 9179052 commit 42718552e717ce6c6b9a4962da19f80bdacad0c7
Showing with 24 additions and 19 deletions.
  1. +8 −3 core/api/shell/files/functions
  2. +16 −16 core/internal/shell/files/functions
@@ -67,6 +67,7 @@ files()
"change owner to=chown"
"change permissions to=chmod"
"change rights to=chmod"
+ "shebang is"
)
if __sm.command.detect "$*" "${__files_commands[@]}"
@@ -83,11 +84,15 @@ files()
;;
(chmod)
_mode="${1}"
- (( $# )) && shift || __sm.log.fail "Mode must follow keywords 'chmod'"
+ (( $# )) && shift || __sm.log.fail "Mode must follow keyword 'chmod'"
;;
(chown)
_owner="${1}"
- (( $# )) && shift || __sm.log.fail "Owner must be provided after keyword 'owner'"
+ (( $# )) && shift || __sm.log.fail "Owner must follow keyword 'chown'"
+ ;;
+ (shebang.is)
+ _string="${1}"
+ (( $# )) && shift || __sm.log.fail "Shebang must be provided after 'shebang is'"
;;
esac
@@ -159,7 +164,7 @@ files()
done
case "${_command}" in
- (contain|containing|contains)
+ (contain|containing|contains|shebang.is)
[[ -n "${_string}" ]] || [[ -n "${_regex}" ]] ||
__sm.log.fail "regexp or string must be given for 'files ${_command}'."
[[ -n "${_files}" ]] || __sm.log.fail "files must be given for 'files ${_command}'."
@@ -205,30 +205,30 @@ __sm.files.exists()
return 0
}
-__sm.files.contain()
+__sm.files.shebang.is()
{
- typeset _string _regex _file
- _string="$1"
- _regex="$2"
+ typeset _string _file
+ _string="${1:-$2}"
shift 2
for _file in $@
do
[[ -f "${_file}" ]] || return 1
+ head -n 1 "${_file}" | grep "#\!${_string}" >/dev/null 2>&1 || return 1
done
+}
- if [[ -n "${_regex}" ]]
- then
- for _file in "${_files[@]}"
- do
- grep "${_regex}" "${_file}" >/dev/null 2>&1 || return 1
- done
- else
- for _file in "${_files[@]}"
- do
- grep "${_string}" "${_file}" >/dev/null 2>&1 || return 1
- done
- fi
+__sm.files.contain()
+{
+ typeset _string _file
+ _string="${1:-$2}"
+ shift 2
+
+ for _file in $@
+ do
+ [[ -f "${_file}" ]] || return 1
+ grep "${_string}" "${_file}" >/dev/null 2>&1 || return 1
+ done
}
__sm.files.containing()

0 comments on commit 4271855

Please sign in to comment.