Skip to content

Commit

Permalink
path.dirArray function major update and added os.is_windows function …
Browse files Browse the repository at this point in the history
…in os module.
  • Loading branch information
OurCodeBase committed Jan 24, 2024
1 parent 5407b89 commit 688dbd2
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 31 deletions.
53 changes: 22 additions & 31 deletions src/file.sh
Original file line number Diff line number Diff line change
Expand Up @@ -126,53 +126,44 @@ file.search(){
grep "${1}" "${2}";
}

# file.search.int(str,file) -> pos
# file.search.pos(str,file) -> pos
# Search given text in file & return you position (eg: 1,2).
# Args:
# str (str) > takes string to search.
# file (str) > takes file path.
file.search.int(){
file.search.pos(){
# return final result.
grep -n "${1}" "${2}" | cut -d: -f1 | head -n 1;
}

# path.dirArray(dir) -> STRIP.
# path.dirArray(dir,*options) -> STRIP.
# Gives you array of files in given directory.
# Args:
# dir (str) > takes directory path.
# --by-time (obj) > Optional: list will be sorted by time.
# --no-extension (obj) > Optional: list have no file extensions.
path.dirArray(){
# taking directory arg from user.
local ARGDir="${1}";
local ARGDir=${1} && shift;
# array list file location.
local UriFile=".Uri";
# check file exist.
path.isdir "${ARGDir}" &&
# listing files to a file.
ls "${ARGDir}" > "${UriFile}" &&
# reading data from array file
# check directory exist.
path.isdir "${ARGDir}" && {
# listing files to a file.
if [[ "${*}" == *"--by-time"* ]]; then
ls -t "${ARGDir}" > "${UriFile}";
shift;
else ls "${ARGDir}" > "${UriFile}";
fi
# no extension of requested files.
if [[ "${*}" == *"--no-extension"* ]]; then
local UriChotuData="$(sed 's/\(.*\)\.\(.*\)/\1/' "${UriFile}")";
echo "${UriChotuData}" > "${UriFile}";
fi
} &&
# reading data from uri file.
file.readlines "${UriFile}" &&
# remove that temp file.
rm "${UriFile}" &&
# return function.
return 0;
}

# path.dirArray.SORT_BY_TIME(dir) -> STRIP.
# Gives you array of files in given directory sorted by time.
# Args:
# dir (str) > takes directory path.
path.dirArray.SORT_BY_TIME(){
# taking directory arg from user.
local ARGDir="${1}";
# array list file location.
local UriFile=".Uri";
# check file exist.
path.isdir "${ARGDir}" &&
# listing files to a file.
ls -t "${ARGDir}" > "${UriFile}" &&
# reading data from array file
file.readlines "${UriFile}" &&
# remove that temp file.
# delete that temp file.
rm "${UriFile}" &&
# return function.
return 0;
Expand Down
6 changes: 6 additions & 0 deletions src/os.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ os.is_termux(){
ls '/data/data/com.termux/files/' &> /dev/null;
}

# os.is_windows() -> bool
# OS is windows or not ?
os.is_windows(){
[[ "$(uname -a)" == *"windows"* ]]
}

# os.is_shell.zsh() -> bool
# Using z-shell or not ?
os.is_shell.zsh(){
Expand Down

0 comments on commit 688dbd2

Please sign in to comment.