You are not logged in.
So, I was thinking about making a script similar to "ls", but a bit more fancy, just the way I want it to work.
So when I've wrote it, it works fine, but there is a bug.
It skips the filenames with spaces like "hello world". Cause I can't figure out how to separate files inside a variable, I ask if somebody may guide me here.
The script:
#!/bin/sh
#lls v1.2
#lls is a sript that works as "ls --group-directories-first" wrapped by a "file" command and some fancy colors.
#
#SCRIPT TAGS:
#DIR open -- means that user can search into this directory.
#DIR closed -- means that user can't search into this directory.
#FILE open -- means that this file is writable and readable.
#FILE closed -- means that this file is not writable and readable.
#FILE open X -- means that this file is writable, readable and executable.
#FILE closed X -- means that this file is executable only.
#FILE seen X -- means that this file is readable and executable, but not writable.
#FILE edit X -- means that this file is writable and executable, but not readable.
#FILE edit only -- means that this file is writable only.
#FILE seen only -- means that this file is readable only.
#FILE zombie -- means that this file is not writable, readable or executable.
#
file_info ( )
{
file=$1
file_prop=$(file -b "$file")
if [ -d "$file" -a -x "$file" ]; then
echo -e "\033[34;5;148m${file##$PWD/}\033[39m \033[34;1;148m> DIR open\033[39m \033[30;5;148m{$file_prop}\033[39m"
tput sgr0
elif [ -d "$file" -a ! -x "$file" ]; then
echo -e "\033[31;5;148m${file##$PWD/}\033[39m \033[31;1;148m> DIR closed\033[39m \033[30;5;148m{$file_prop}\033[39m"
tput sgr0
fi
if [ -f "$file" -a -r "$file" -a -w "$file" -a ! -x "$file" ]; then
echo -e "${file##$PWD/} \033[32;1;148m> FILE open\033[39m \033[30;5;148m{$file_prop}\033[39m"
tput sgr0
# elif [ -f "$file" -a ! -w "$file" -a ! -r "$file" ]; then
#echo -e "\033[31;5;148m${file##$PWD/}\033[39m \033[31;1;148m> FILE closed\033[39m \033[30;5;148m{$file_prop}\033[39m"
elif [ -f "$file" -a ! -w "$file" -a ! -r "$file" -a -x "$file" ]; then
echo -e "\033[31;5;148m${file##$PWD/}\033[39m \033[31;1;148m> FILE closed X\033[39m \033[30;5;148m{$file_prop}\033[39m"
elif [ -f "$file" -a -w "$file" -a -r "$file" -a -x "$file" ]; then
echo -e "\033[33;5;148m${file##$PWD/}\033[39m \033[33;1;148m> FILE open X\033[39m \033[30;5;148m{$file_prop}\033[39m"
elif [ -f "$file" -a ! -w "$file" -a -r "$file" -a -x "$file" ]; then
echo -e "\033[31;5;148m${file##$PWD/}\033[39m \033[31;1;148m> FILE seen X\033[39m \033[30;5;148m{$file_prop}\033[39m"
elif [ -f "$file" -a -w "$file" -a ! -r "$file" -a -x "$file" ]; then
echo -e "\033[35;5;148m${file##$PWD/}\033[39m \033[35;1;148m> FILE edit X\033[39m \033[30;5;148m{$file_prop}\033[39m"
elif [ -f "$file" -a -w "$file" -a ! -r "$file" -a ! -x "$file" ]; then
echo -e "\033[35;5;148m${file##$PWD/}\033[39m \033[35;1;148m> FILE edit only\033[39m \033[30;5;148m{$file_prop}\033[39m"
elif [ -f "$file" -a ! -w "$file" -a -r "$file" -a ! -x "$file" ]; then
echo -e "\033[31;5;148m${file##$PWD/}\033[39m \033[31;1;148m> FILE seen only\033[39m \033[30;5;148m{$file_prop}\033[39m"
elif [ -f "$file" -a ! -w "$file" -a ! -r "$file" -a ! -x "$file" ]; then
echo -e "\033[30;5;148m${file##$PWD/}\033[39m \033[30;1;148m> FILE zombie\033[39m \033[30;5;148m{$file_prop}\033[39m"
tput sgr0
fi
}
curdir=$1
if [ -z "$curdir" ]; then
curdir=$PWD
elif [ -f $curdir ]; then
echo "Its a file!"
exit 0
fi
dirs=`ls --group-directories-first $curdir`
for files in $dirs; do
file_info "$curdir/$files"
done
Last edited by tasty_minerals (2011-10-23 09:39:32)
lenovo thinkpad EDGE 13'
Offline
The last part: seems to be the culprit
dirs=`ls --group-directories-first`
for file in $dirs; do
file_info "$curdir/$file"
done
Check
dirs=`ls --group-directories-first`
for file in $dirs; do
echo $file
done
You shouldn't parse ls output.
Offline
Here's why http://mywiki.wooledge.org/ParsingLs
Offline
I'm very sorry, posted a bad copy of the script, that doesn't work. Fixed
lenovo thinkpad EDGE 13'
Offline
Ahhh, thank you guys, maybe I think about using "find" instead, its seems like a better choice.
Last edited by tasty_minerals (2011-10-23 09:35:52)
lenovo thinkpad EDGE 13'
Offline
I'm very sorry, posted a bad copy of the script, that doesn't work. Fixed
Your script seems to work for me - I got the colors and blinking ...
Ahhh, thank you guys, maybe I should use "find" then.
Yes, this should fix it.
Offline
tasty_minerals wrote:I'm very sorry, posted a bad copy of the script, that doesn't work. Fixed
Your script seems to work for me - I got the colors and blinking ...
tasty_minerals wrote:Ahhh, thank you guys, maybe I should use "find" then.
Yes, this should fix it.
blinking? ^^
no, blinking is a bug of xterm and "file" utility, try to use any other terminal, like lxterminal, or lilyterm or some vte based. I still couldn't figure out the blinking thing.
By the way "lls" does accept arguments like dirs: "lls /usr/share/". Just in case.
lenovo thinkpad EDGE 13'
Offline
I'm using rxvt-unicode .... and I'm glad it's a bug and not something you designed as a feature ;P
Offline
lol, ok, I'm glad that you're glad
lenovo thinkpad EDGE 13'
Offline