From 688dbd2fc6a321efae4f74d788bd40c30ce7e227 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?h=CE=B1rsh=20v=CE=B1ir=CE=B1gi?= Date: Thu, 25 Jan 2024 01:24:34 +0530 Subject: [PATCH] path.dirArray function major update and added os.is_windows function in os module. --- src/file.sh | 53 ++++++++++++++++++++++------------------------------- src/os.sh | 6 ++++++ 2 files changed, 28 insertions(+), 31 deletions(-) diff --git a/src/file.sh b/src/file.sh index 60d49a0..414b1c6 100644 --- a/src/file.sh +++ b/src/file.sh @@ -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; diff --git a/src/os.sh b/src/os.sh index 69277dc..8d745ef 100644 --- a/src/os.sh +++ b/src/os.sh @@ -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(){