Hi All.
I have a simple script to search applications. It use function infoku, infoku-pilih, jalan, and jalan-tree.
Actually, infoku and infoku-pilih is information about Comment and Name of application, but different on the input. infoku just read top of tree, but infoku-pilih read from selection of tree.
jalan and jalan-tree is to run the exec, but jalan read the top of tree, and jalan-tree read from selection of tree.
Is it possible to just use two function info and jalan? How? Thank you.
This is my code
Code: Select all
#!/bin/bash
# 211015 simple muksearch
export wd=/tmp/sku #working directory
mkdir -p "$wd"
ls /usr/share/applications/*.desktop>"$wd"/apps_file
cut -d\/ -f5 "$wd"/apps_file|sed 's/\.desktop//' > "$wd"/apps_tree
cari(){
grep -ie "Name=.*$e" -e "Comment=.*$e" -e "Exec=.*$e" /usr/share/applications/* -l > "$wd"/apps_cari
cut -d\/ -f5 "$wd"/apps_cari |sed 's/\.desktop//' > "$wd"/apps_tree
app_top=`head -1 "$wd"/apps_cari`
infoku "$app_top"
}
export -f cari
infoku(){
app_name=`grep -ie "^Name=" "$1"|cut -d\= -f2`
printf "<b>$app_name</b>" > "$wd"/app_name
grep -ie "^Comment=" "$1"|cut -d\= -f2|tr -d '\n' > "$wd"/app_comment
icon=`grep -ie "^Icon=" "$1"|cut -d\= -f2`
#~ echo icon = "$icon"
if [[ "$icon" == *\/* ]];then
ln -sf "$icon" "$wd"/app_icon
else
ic=`find /usr/share/pixmaps/ /usr/share/icons/ -type f -name "$icon*" -print|tail -1`
#~ echo "$ic"
if [ "$ic" == "" ];then
ln -sf /usr/share/pixmaps/deb_logo.png "$wd"/app_icon
else
ln -sf "$ic" "$wd"/app_icon
fi
fi
}
export -f infoku
infoku-pilih(){
app=/usr/share/applications/"$t".desktop
app_name=`grep -ie "^Name=" "$app"|cut -d\= -f2`
printf "<b>$app_name</b>" > "$wd"/app_name
grep -ie "^Comment=" "$app"|cut -d\= -f2|tr -d '\n' > "$wd"/app_comment
icon=`grep -ie "^Icon=" "$app"|cut -d\= -f2`
#~ echo icon = "$icon"
if [[ "$icon" == *\/* ]];then
ln -sf "$icon" "$wd"/app_icon
else
ic=`find /usr/share/pixmaps/ /usr/share/icons/ -type f -name "$icon*" -print|tail -1`
#~ echo "$ic"
if [ "$ic" == "" ];then
ln -sf /usr/share/pixmaps/deb_logo.png "$wd"/app_icon
else
ln -sf "$ic" "$wd"/app_icon
fi
fi
}
export -f infoku-pilih
jalan(){
app=`head -1 "$wd"/apps_cari`
#~ echo "$app"
di_terminal=`grep -ie "^Terminal=true" "$app"`
exe=`grep -e "Exec=" "$app"|cut -d\= -f2|sed 's/%.*//'`
if [ "$di_terminal" ];then
x-terminal-emulator -e "$exe"
else
eval "$exe"&
fi
}
export -f jalan
jalan-tree(){
app=/usr/share/applications/"$t".desktop
#~ echo "$app"
di_terminal=`grep -ie "^Terminal=true" "$app"`
exe=`grep -e "Exec=" "$app"|cut -d\= -f2|sed 's/%.*//'`
if [ "$di_terminal" ];then
x-terminal-emulator -e "$exe"
else
eval "$exe"&
fi
}
export -f jalan-tree
export guisku='
<window height-request="400" width-request="400" title="Search app" \
icon-name="gtk-find" window_position="1" skip_taskbar_hint="true">
<vbox>
<entry>
<action>cari</action>
<action>refresh:t</action>
<action>refresh:txt_name</action>
<action>refresh:txt_comment</action>
<action signal="activate">jalan</action>
<action signal="activate">EXIT:exit</action>
<variable>e</variable>
</entry>
<tree rules-hint="true" headers-visible="false" hover-selection="true">
<action signal="button-release-event">jalan-tree</action>
<action signal="button-release-event">EXIT:exit</action>
<action signal="cursor_changed">infoku-pilih</action>
<action signal="cursor_changed">refresh:txt_name</action>
<action signal="cursor_changed">refresh:txt_comment</action>
<action signal="cursor_changed">refresh:b</action>
<action signal="button-release-event">jalan-tree</action>
<action>jalan-tree</action>
<action>EXIT:exit</action>
<input file>'"$wd"'/apps_tree</input>
<variable>t</variable>
</tree>
<hbox>
<vbox>
<text xalign="1" use-markup="true">
<input file>'"$wd"'/app_name</input>
<variable>txt_name</variable>
</text>
<text xalign="1">
<input file>'"$wd"'/app_comment</input>
<variable>txt_comment</variable>
</text>
</vbox>
<button relief="2">
<width>32</width>
<input file>'"$wd"'/app_icon</input>
<variable>b</variable>
</button>
</hbox>
</vbox>
<action signal="key-press-event" condition="command_is_true([ $KEY_SYM = Escape ] && echo true )">exit:EXIT</action>
</window>'
aktif=`pgrep -f guisku`
if [ "$aktif" != "" ];then
kill $aktif
else
gtkdialog -p guisku
fi