Skip to content

Commit

Permalink
Merge pull request #6 from realpvn/improve-autocomplete
Browse files Browse the repository at this point in the history
Improve Autocomplete
  • Loading branch information
whopavan authored Oct 9, 2021
2 parents 9c71a46 + 86dc5d3 commit f1a974c
Show file tree
Hide file tree
Showing 9 changed files with 373 additions and 63 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ gfinstall [options] [fontNameHere]
Options:
-l | --local To Install fonts locally
-v | --version Check gfinstall version
-ul | --update-list To update local google font list (this helps autocompletion)
-h | --help Displays available options
Examples:
Expand Down
71 changes: 58 additions & 13 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ currentVersion() {
makeDeb () {
echo "Running make"
clean
updateGFList
read -p "Have you updated version? (Y/N): " verUpdate
case $verUpdate in
[Yy]* ) echo "Continuing....";;
Expand Down Expand Up @@ -43,7 +44,7 @@ buildDebSource () {

buildDebBinary () {
echo "[!] Binary file cannot be uploaded to PPA"
read -p "This will deleted any deb source files, do you want to proceed? (Y/N): " cleanNow
read -p "This will delete any deb source files, do you want to proceed? (Y/N): " cleanNow
case $cleanNow in
[Yy]* ) echo "Continuing....";;
[Nn]* ) echo "You must clean to build binary, exiting..."
Expand Down Expand Up @@ -71,6 +72,48 @@ clean () {
rm -f ../gfinstall_*
}

fetchLatestGF() {
# This function updates gflist with all google fonts available
# To use this you must set GOOGLE_API_KEY env variable

# In the first time `apiData=` we get data from the api
# Then we parse api data and copy it to gflist file
# - `echo ${apiData,,}` will convert everything to lowercase
# - `jq -r` is responsible for parsing api data (keep in mind that all data have been lowered before parsing,
# might be bad but it stays till I find better solution)
# - `tr -d ' '` will get rid of all the spaces in between names and write the output to gflist file

apiData=`curl -s "https://www.googleapis.com/webfonts/v1/webfonts?key=$GOOGLE_API_KEY&sort=alpha"`
echo ${apiData,,} | jq -r '.items[].family' | tr -d ' ' > fonts_list/gflist

if [ $? != 0 ]
then
return 1
fi
return 0
}

updateGFList() {
echo "Updating Google Fonts list"
fetchLatestGF

if [ $? != 0 ]
then
printFailed "Failed to fetch latest Google Fonts"
return 1
fi

newFontsList=`echo $(cat fonts_list/gflist)`
sed -i '/^fontsList=*/c\fontsList="'"$newFontsList"'"' 'gfinstall.bash'

if [ $? != 0 ]
then
printFailed "Failed to update Google Fonts list"
return 1
fi
return 0
}

uploadPPA () {
echo "Current version: $fullCurVer"
read -p "Is the current version correct? (Y/N): " verCheck
Expand All @@ -88,18 +131,20 @@ then
currentVersion
PARAM=$1
case $PARAM in
-ds | --debSource ) buildDebSource;
exit;;
-db | --debBinary ) buildDebBinary;
exit;;
-c | --clean ) clean;
exit;;
-d | --debug ) debug;
exit;;
-u | --uploadPPA ) uploadPPA;
exit;;
* ) echo -e "Usage:\n-ds | --debSource:\t Generates debian source file\n-db | --debBinary:\t Generates debian binary file\n-sn | --snap:\t\t Generates Snap Package\n-c | --clean:\t\t Cleans directory, removes all build files etc\n-u | --uploadPPA:\t Uploads source file to PPA";
exit;;
-ds | --debSource ) buildDebSource;
exit;;
-db | --debBinary ) buildDebBinary;
exit;;
-c | --clean ) clean;
exit;;
-d | --debug ) debug;
exit;;
-ul | --update-list ) updateGFList;
exit;;
-u | --uploadPPA ) uploadPPA;
exit;;
* ) echo -e "Usage:\n-ds | --debSource:\t Generates debian source file\n-db | --debBinary:\t Generates debian binary file\n-sn | --snap:\t\t Generates Snap Package\n-c | --clean:\t\t Cleans directory, removes all build files etc\n-u | --uploadPPA:\t Uploads source file to PPA";
exit;;
esac
fi
echo -e "Usage:\n-ds | --debSource:\t Generates debian source file\n-db | --debBinary:\t Generates debian binary file\n-sn | --snap:\t Generates Snap Package\n-c | --clean:\t\t Cleans directory, removes all build files etc\n-u | --uploadPPA:\t Uploads source file to PPA";
7 changes: 7 additions & 0 deletions debian/changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
gfinstall (1.6-1) focal; urgency=medium

* Major improvements to auto completion
* Removed gflist.txt file

-- Pavan Kumar <[email protected]> Sat, 09 Oct 2021 16:29:14 +0530

gfinstall (1.5-1) focal; urgency=medium

* Fixed invalid version number being displayed
Expand Down
2 changes: 1 addition & 1 deletion debian/files
Original file line number Diff line number Diff line change
@@ -1 +1 @@
gfinstall_1.5-1_source.buildinfo utils optional
gfinstall_1.6-1_source.buildinfo utils optional
1 change: 0 additions & 1 deletion debian/install
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
gfinstall usr/bin
gflist.txt usr/share/bash-completion/completions
gfinstall.bash usr/share/bash-completion/completions
Loading

0 comments on commit f1a974c

Please sign in to comment.