-
Notifications
You must be signed in to change notification settings - Fork 2
/
pikeru
executable file
·132 lines (118 loc) · 3.08 KB
/
pikeru
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
124
125
126
127
128
129
130
131
132
#!/bin/bash
# This script needs a venv in this direcotry. It will try to create one for you if you don't have one.
# It logs to /tmp/pk.log if you set debug=1 below.
debug=0
logfile=/tmp/pk.log
# LD_PRELOAD is set by the browser and can interfere with an opencv lib used to display video frames
unset LD_PRELOAD
DIR="$(pwd)"
cd "$(dirname "$(readlink -f "$0")")"
TITLE="File Picker"
MODE="files"
MIME_LIST=""
update=0
xconfig="${XDG_CONFIG_HOME:-$HOME/.config}/xdg-desktop-portal"
usage(){
cat << EOF
$0 [ -t title -m mode -p path -i mimes -u -h -x ]
usage options:
-t <title>
Set the title for the filepicker window
-m <mode>
Set the mode for file selection. One of [file files save dir]. Default is 'files'
-p <path>
Initial path. Should be a directory when not in save mode, otherwise a file path. default is $HOME
-i <mimes>
Space separaated list if mime types to filter for
-h
Show this help message
setup options:
-u
Update the python dependencies. Useful if deps were added after a git pull
-x
Configure xdg-desktop-portal to use pikeru. This installs portals.conf in ${xconfig}.
This can be reverted with '$(basename $0) -r'
-r
Revert xdg-portal to use your old filepicker. You can turn pikeru back on with '$(basename $0) -x'
EOF
exit
}
portalconfig(){
bash ./xdg_portal/contrib/setconfig.sh
exit
}
remove(){
if [ -r $xconfig/portals.conf.orig ]; then
mv $xconfig/portals.conf.orig $xconfig/portals.conf
elif [ ! -r "$xconfig/portals.conf" ] || ! grep -q pikeru "$xconfig/portals.conf"; then
echo -e "XDG portal is not configured to use pikeru. Not changing anything." > /dev/stderr
echo "You can enable pikeru with -x" > /dev/stderr
exit
else
rm $xconfig/portals.conf
fi
echo 'Pikeru filepicker disabled. Re-enable with -x'
systemctl --user restart xdg-desktop-portal.service
exit
}
[ $debug = 1 ] && echo "launcher args: $*" >> $logfile
while getopts "e:t:m:p:i:uhxr" opt; do
case $opt in
e)
PARENT="$OPTARG"
;;
t)
TITLE="$OPTARG"
;;
m)
MODE="$OPTARG"
;;
p)
DIR="$OPTARG"
;;
i)
MIME_LIST="$OPTARG"
;;
u)
update=1
;;
h)
usage
;;
r)
remove
;;
x)
portalconfig
;;
\?)
echo "Invalid option: -$opt $OPTARG" | tee -a $logfile > /dev/stderr
exit 1
;;
esac
done
if [[ ! "$MODE" =~ ^(file|files|dir|save)$ ]]; then
echo "Error: Invalid mode flag value (-m). It should be one of [file files dir save]." | tee -a $logfile > /dev/stderr
exit 1
fi
if [ ! -f "./venv/bin/activate" ]; then
echo 'No venv found. Creating one now...' > /dev/stderr
python3 -m venv venv
. ./venv/bin/activate
pip3 install -r requirements.txt
else
. ./venv/bin/activate
[ $update = 1 ] && pip3 install -r requirements.txt
fi
cmd="python ./main.py \
--mode '${MODE}' \
--path \"${DIR}\" \
--title '${TITLE}' \
--mime_list '${MIME_LIST[@]:-}' \
--parent '${PARENT:-}'"
[ $debug = 1 ] && echo "cmd: $cmd" >> $logfile
if [ -r ./postprocess.sh ] && [ ! -z "$POSTPROCESS_DIR" ]; then
eval "$cmd"|bash ./postprocess.sh
else
eval "$cmd"
fi