Add sort and sorting-method option
This commit is contained in:
parent
5c3781ceb6
commit
a01056d18a
45
snippy
45
snippy
@ -51,7 +51,6 @@
|
|||||||
set -o errexit -o pipefail -o nounset
|
set -o errexit -o pipefail -o nounset
|
||||||
|
|
||||||
readonly snippets_directory=${XDG_CONFIG_HOME:-$HOME/.config}/snippy
|
readonly snippets_directory=${XDG_CONFIG_HOME:-$HOME/.config}/snippy
|
||||||
readonly rofi_args=(-no-lazy-grab -dmenu -i -sort -sorting-method fzf -async-pre-read 20 -theme-str 'element-icon { size: 2.35ch;}' -kb-accept-custom "" -kb-custom-1 "Ctrl+Return")
|
|
||||||
readonly fzf_args=(--select-1 --reverse --inline-info --multi --preview '( bat --style auto --color always --language bash {} 2> /dev/null || highlight --force -O ansi -l {} 2> /dev/null ) | head -200' -1)
|
readonly fzf_args=(--select-1 --reverse --inline-info --multi --preview '( bat --style auto --color always --language bash {} 2> /dev/null || highlight --force -O ansi -l {} 2> /dev/null ) | head -200' -1)
|
||||||
readonly focus_wait=0.15
|
readonly focus_wait=0.15
|
||||||
|
|
||||||
@ -73,9 +72,12 @@ readonly normal="\e[0m"
|
|||||||
readonly bold="\e[1m"
|
readonly bold="\e[1m"
|
||||||
readonly underline="\e[4m"
|
readonly underline="\e[4m"
|
||||||
|
|
||||||
|
# Default
|
||||||
script_content=false
|
script_content=false
|
||||||
action=gui
|
action=gui
|
||||||
snippet=
|
snippet=
|
||||||
|
rofi_sort="-sort"
|
||||||
|
rofi_sort_method="-sorting-method fzf"
|
||||||
|
|
||||||
# smarty like template engine which executes inline bash in (bashdown) strings (replaces variables with values e.g.)
|
# smarty like template engine which executes inline bash in (bashdown) strings (replaces variables with values e.g.)
|
||||||
# @link http://github.com/coderofsalvation/bashdown
|
# @link http://github.com/coderofsalvation/bashdown
|
||||||
@ -194,7 +196,9 @@ usage() {
|
|||||||
echo -e "\tSnippy snippets manager"
|
echo -e "\tSnippy snippets manager"
|
||||||
|
|
||||||
echo "Options"
|
echo "Options"
|
||||||
echo -e "\t-h, --help Show help"
|
echo -e "\t-h, --help: Show help"
|
||||||
|
echo -e "\t-s, --sort: true or false Sort snippet in rofi (default)"
|
||||||
|
echo -e "\t-m, --sorting-method: fzf (default) or levenshtein"
|
||||||
|
|
||||||
echo "Actions"
|
echo "Actions"
|
||||||
echo -ne "\t${bold}gui${normal}"
|
echo -ne "\t${bold}gui${normal}"
|
||||||
@ -228,16 +232,37 @@ parse_options() {
|
|||||||
-h | --help)
|
-h | --help)
|
||||||
usage
|
usage
|
||||||
;;
|
;;
|
||||||
--) # end argument parsing
|
-s | --sort)
|
||||||
|
if [ "$2" = true ] || (( $2 == 1 )); then
|
||||||
|
rofi_sort="-sort"
|
||||||
|
elif [ "$2" = false ] || (( $2 == 0 )); then
|
||||||
|
rofi_sort="-no-sort"
|
||||||
|
else
|
||||||
|
echo -e "Sort should be set to ${bold}true${normal} or ${bold}false${normal}"
|
||||||
|
echo
|
||||||
|
usage
|
||||||
|
fi
|
||||||
shift
|
shift
|
||||||
|
;;
|
||||||
|
-m | --sorting-method)
|
||||||
|
if [ "$2" = fzf ] || [ "$2" = levenshtein ]; then
|
||||||
|
rofi_sort_method="-sorting-method $2"
|
||||||
|
else
|
||||||
|
echo -e "Sorting method should be set to ${bold}fzf${normal} or ${bold}levenshtein${normal}"
|
||||||
|
echo
|
||||||
|
usage
|
||||||
|
fi
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
--) # end argument parsing
|
||||||
break
|
break
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
action="$1"
|
action="$1"
|
||||||
shift
|
|
||||||
return
|
return
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
shift
|
||||||
done
|
done
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -467,6 +492,18 @@ run() {
|
|||||||
main() {
|
main() {
|
||||||
parse_options "$@"
|
parse_options "$@"
|
||||||
|
|
||||||
|
readonly rofi_args=(
|
||||||
|
-no-lazy-grab
|
||||||
|
-dmenu
|
||||||
|
"$rofi_sort"
|
||||||
|
"$rofi_sort_method"
|
||||||
|
-async
|
||||||
|
-pre-read 20
|
||||||
|
-theme-str 'element-icon { size: 2.35ch;}'
|
||||||
|
-kb-accept-custom ""
|
||||||
|
-kb-custom-1 "Ctrl+Return"
|
||||||
|
)
|
||||||
|
|
||||||
cd "${snippets_directory}" || exit
|
cd "${snippets_directory}" || exit
|
||||||
|
|
||||||
case "$action" in
|
case "$action" in
|
||||||
|
Loading…
Reference in New Issue
Block a user