-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlsc2ls_c
executable file
·65 lines (55 loc) · 1.1 KB
/
lsc2ls_c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/bin/ksh
### Description: lsc2ls_c -- transform LSCOLORS to LS_COLORS
### Author: Michael Grubb
### Modeline: vi:set ai ts=4 sw=4 ft=sh:
### Usage: eval `lsc2ls_c`
_colors="$LSCOLORS"
ls_color_names=("di" "ln" "so" "pi" "ex" "bd" "cd" "su" "sg" "tw" "ow")
lscolor_chars=(
[a]='30'
[b]='31'
[c]='32'
[d]='33'
[e]='34'
[f]='35'
[g]='36'
[h]='37'
[x]='00'
)
makebold () {
if echo $1 | grep -q '[A-Z]'
then
echo "01;$2"
else
echo "$2"
fi
}
bgcolor () {
c=`echo $1 | tr 'A-Z' 'a-z'`
cc="${lscolor_chars[$c]}"
if [ "$cc" != "00" -a -n "$cc" ]
then
let 'cc = cc + 10'
fi
makebold $1 $cc
}
fgcolor () {
c=`echo $1 | tr 'A-Z' 'a-z'`
cc="${lscolor_chars[$c]}"
makebold $1 $cc
}
ls_colors=
for (( fld = 0 ; fld < 11 ; fld = fld + 1 ))
do
color=`echo $_colors | cut -c 1,2`
_colors=`echo $_colors | sed -e 's/^..//'`
fg=$(fgcolor $(echo $color | cut -c 1))
bg=$(bgcolor $(echo $color | cut -c 2))
if [ $fld -eq 0 ]
then
ls_colors="${ls_color_names[$fld]}=$fg;$bg"
else
ls_colors="${ls_colors}:${ls_color_names[$fld]}=$fg;$bg"
fi
done
echo "LS_COLORS=\"$ls_colors\"; export LS_COLORS"