-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpwb_xdg
executable file
·123 lines (100 loc) · 2.77 KB
/
pwb_xdg
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#!/usr/bin/env bash
enable ate
enable pwb
source <( pwb_sources \
ate_exit_on_error \
pwb_exit_on_error \
ate_get_index_with_key \
ate_confirm_functions \
ate_display_ate_table \
)
declare MARGIN_COLOR=$'\e[48;2;64;64;64m'
############################################################
# This script presents a table of desktop files that
# are used to access files that are identified as the
# appropriate mime type.
#
# This script is an example of how to parse data use Bash
# regular expression methods, among other things. It uses
# the convenient function 'pwb_display_ate_table' to show
# formatted output.
############################################################
##########################
### TABLE PREPERATIONS ###
##########################
get_data_dirs()
{
local -n gdd_array="$1"
gdd_array=()
local IFS=':'
local -a tdirs=( $XDG_DATA_DIRS )
IFS='/'
for dir in "${tdirs[@]}"; do
local -a parts=( $dir )
parts+=( applications )
local candidate="${parts[*]}"
if [ -d "$candidate" ]; then
gdd_array+=( "$candidate" )
fi
done
}
read_desktop_info()
{
local -n rdi_hash="$1"
local path="$2"
rdi_hash=()
local line firstchar
local -a pair
local IFS='='
while read -r line; do
# Skip empty lines
if [ "${#line}" -eq 0 ]; then
continue
fi
# skip section heads '[' and comments '#'
firstchar="${line:0:1}"
if [[ \[\# =~ "$firstchar" ]]; then
continue
fi
pair=( $line )
local key="${pair[0]}"
local value="${pair[1]}"
rdi_hash["$key"]="$value"
done < "$path"
}
load_table()
{
local table_name="$1"
ate get_array_name "$table_name"
local -n lt_array="$ATE_VALUE"
local -a data_dirs
get_data_dirs data_dirs
local -A dt_contents
for dir in "${data_dirs[@]}"; do
# Get number of path prefix chars to remove
# for the current directory
local -i dir_len="${#dir}"
(( ++dir_len ))
local exec_str term_flag
local -a files=( "${dir}/"*.desktop )
for file in "${files[@]}"; do
read_desktop_info dt_contents "$file"
exec_str="${dt_contents[Exec]}"
if [[ "${dt_contents[Terminal]}" == "true" ]]; then
term_flag="yes"
else
term_flag="no"
fi
lt_array+=( "${file:$dir_len}" "$dir" "$exec_str" "$term_flag" )
done
done
ate index_rows "$table_name"
ate_exit_on_error
}
declare DT_TABLE
ate declare DT_TABLE 4
ate_exit_on_error
load_table DT_TABLE
pwb init
pwb_display_ate_table DT_TABLE
pwb restore