Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

api file readlinks

  • Loading branch information...
commit 07abf1a38d7395fd7e31088153a4438dfb9f0a85 1 parent 6bbcc16
@mpapis mpapis authored
View
3  core/api/shell/files/functions
@@ -35,6 +35,7 @@
# file open {file}
# file md5 {file}
# file(s) expand {file} # eg. expand to include 'full/absolute' path
+# file readlinks {file}
# file search {file} # NIY
# file(s) source {file}
# file remove {file}
@@ -177,7 +178,7 @@ files()
else return 1
fi
;;
- (open|md5|enter|join|expand|search|within|in|source|empty|nonempty|exist|exists|remove|create|touch|are.*|sha.*)
+ (open|md5|enter|join|expand|readlinks|search|within|in|source|empty|nonempty|exist|exists|remove|create|touch|are.*|sha.*)
[[ -n "${_files}" ]] || __sm.log.fail "files must be given for 'files ${_command}'."
if __sm.files.${_command} "${_files[@]}"
then return 0
View
10 core/internal/shell/files/files_comment_test.sh
@@ -0,0 +1,10 @@
+#!/usr/bin/env zsh
+
+source test-sm
+includes internal/files
+
+touch "${sm_temp_path}/a"
+ln -s "${sm_temp_path}/a" "${sm_temp_path}/b"
+ln -s "${sm_temp_path}/b" "${sm_temp_path}/c"
+
+__sm.files.readlinks "${sm_temp_path}/c" # match=/\/a$/
View
10 core/internal/shell/files/functions
@@ -512,3 +512,13 @@ __sm.files.touch()
done
return 0
}
+
+__sm.files.readlinks()
+{
+ typeset _file_name
+ _file_name="$1"
+ while [[ -L "$_file_name" ]]
+ do _file_name="$( readlink "${_file_name}" )"
+ done
+ printf "${_file_name}\n"
+}

1 comment on commit 07abf1a

@drnic

Please add some inline or external docs for how to use this. The code certainly (to me) isn't self-explanatory.

Please sign in to comment.
Something went wrong with that request. Please try again.