Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add mac friendly options in script (fix bashisms, file paths, need OSx tester) #11

Closed
tallguyjenks opened this issue Apr 21, 2020 · 52 comments · Fixed by #26
Closed

add mac friendly options in script (fix bashisms, file paths, need OSx tester) #11

tallguyjenks opened this issue Apr 21, 2020 · 52 comments · Fixed by #26
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@tallguyjenks
Copy link
Owner

No description provided.

@tallguyjenks tallguyjenks added enhancement New feature or request help wanted Extra attention is needed labels Apr 21, 2020
@tallguyjenks
Copy link
Owner Author

@jhonkaman someone on reddit who was messing with the script got an answer for me... maybe.. what do you see in you ~/Library/Application Support directory? are there data files in there used by programs?

@grokskookum
Copy link

Mac puts files here (example firefox)

myself:~ dznutz$ sudo find ~/Library/ -type f |grep -i firefox | cut -f 1-8 -d / | uniq -c |sort -n
1 /Users/dznutz/Library//Application Support/Firefox/installs.ini
1 /Users/dznutz/Library//Application Support/Firefox/profiles.ini
1 /Users/dznutz/Library//Application Support/WebEx Folder/Add-ons
1 /Users/dznutz/Library//Caches/org.mozilla.firefox/Cache.db
1 /Users/dznutz/Library//Caches/org.mozilla.firefox/Cache.db-shm
1 /Users/dznutz/Library//Caches/org.mozilla.firefox/Cache.db-wal
1 /Users/dznutz/Library//Caches/org.mozilla.firefox/WebKitCache
1 /Users/dznutz/Library//Preferences/org.mozilla.firefox.plist
1 /Users/dznutz/Library//Saved Application State/org.mozilla.firefox.savedState/data.data
1 /Users/dznutz/Library//Saved Application State/org.mozilla.firefox.savedState/window_1.data
1 /Users/dznutz/Library//Saved Application State/org.mozilla.firefox.savedState/windows.plist
3 /Users/dznutz/Library//Caches/Mozilla/updates
14 /Users/dznutz/Library//Application Support/Firefox/Crash Reports
529 /Users/dznutz/Library//Caches/Firefox/Profiles
2064 /Users/dznutz/Library//Application Support/Firefox/Profiles

@tallguyjenks
Copy link
Owner Author

lol @grokskookum, i dig the username haha. it looks like Library may be the place, your links have 2 slashes between library and things lke Application support, is there a missing field in there?

@jhonkaman
Copy link

@tallguyjenks there are a lot of folders in ~/Library/Application Support. It looks like there is 1 folder for each application I have installed. If I look inside the folders, I see different types of files, but I do see a lot of .plist files, which I think fall under the category of data files that you're referring to.

@tallguyjenks
Copy link
Owner Author

@jhonkaman the single folder per application was probably what i was looking for. in that case, can you install the dependencies listed in the readme fzf and bat? and if so do they run as expected in your cli?

@jhonkaman
Copy link

Yes, I'll try installing them now.

@jhonkaman
Copy link

It looks like fzf and bat are working as expected, but I'm not sure how to get them to work together at the moment.

@tallguyjenks
Copy link
Owner Author

no need, the script should take care of that, but i need to adjust for mac, ill do that tonight, finishing my work day and errands at the moment

@tallguyjenks
Copy link
Owner Author

@jhonkaman or @grokskookum what is the output of the uname command in your terminal, and also the uname -s command

@jhonkaman
Copy link

The output for both of those commands is Darwin for me.

@tallguyjenks
Copy link
Owner Author

excellent, then i may have a fix with a simple case statement. then ill need to you add the new script to a place in your $PATH then run it and see if anything breaks, will update you at that point

@tallguyjenks
Copy link
Owner Author

tallguyjenks commented Apr 26, 2020

@jhonkaman can you run this command in your terminal echo "$HOME" and tell me the output, and what terminal emulator are you running? and also how did you install fzf and bat onto your machine?

@tallguyjenks
Copy link
Owner Author

@jhonkaman @grokskookum ive pushed a mac friendly version to master, please test and see if it works as expected. put the flash script in your $PATH somewhere and run it :)

@jhonkaman
Copy link

For your previous question, echo $HOME outputs /Users/Javier.

The terminal emulator is just the built-in Terminal app on macOS.

I installed fzf and bat using Homebrew. I'll try installing your script tomorrow.

@tallguyjenks
Copy link
Owner Author

perfect, if it works, then with homebrew installation of the 2 programs, we'll be good to go on mac!

@jhonkaman
Copy link

I got the following output when I ran flash:

/usr/local/bin/flash: line 108: [: /Users/Javier/Library/Application: binary operator expected
/usr/local/bin/flash: line 119: cd: /Users/Javier/Library/Application Support/flash: No such file or directory
find: illegal option -- m
usage: find [-H | -L | -P] [-EXdsx] [-f path] path ... [expression]
       find [-H | -L | -P] [-EXdsx] -f path [path ...] [expression]
touch: /Users/Javier/Library/Application Support/flash/.highscore: No such file or directory
touch: /Users/Javier/Library/Application Support/flash/.reviews: No such file or directory
find: illegal option -- m
usage: find [-H | -L | -P] [-EXdsx] [-f path] path ... [expression]
       find [-H | -L | -P] [-EXdsx] -f path [path ...] [expression]

Maybe I messed up the installation.

@tallguyjenks
Copy link
Owner Author

@jhonkaman no i see what went wrong, the mac file path has a space in it and i didnt quote one of the instances of the variable holding the file path, i just fixed, grab the latest commit of the script and try again

@jhonkaman
Copy link

Got a little farther:

No .local/share/flash directory, make it? Y/N
y
touch: Support/flash/deck.csv: No such file or directory
touch: Support/flash/.highscore: No such file or directory
touch: Support/flash/.reviews: No such file or directory
find: illegal option -- m
usage: find [-H | -L | -P] [-EXdsx] [-f path] path ... [expression]
       find [-H | -L | -P] [-EXdsx] -f path [path ...] [expression]
find: illegal option -- m
usage: find [-H | -L | -P] [-EXdsx] [-f path] path ... [expression]
       find [-H | -L | -P] [-EXdsx] -f path [path ...] [expression]

@tallguyjenks
Copy link
Owner Author

@jhonkaman found'em, more unquoted paths, thanks apple... lol rinse and repeat, try again with latest build

@jhonkaman
Copy link

Ok. Still getting these errors:

find: illegal option -- m
usage: find [-H | -L | -P] [-EXdsx] [-f path] path ... [expression]
       find [-H | -L | -P] [-EXdsx] -f path [path ...] [expression]
find: illegal option -- m
usage: find [-H | -L | -P] [-EXdsx] [-f path] path ... [expression]
       find [-H | -L | -P] [-EXdsx] -f path [path ...] [expression]

@tallguyjenks
Copy link
Owner Author

okay try again, i switched some of the command substitution quoting

and can you post the output of man find for me?

@jhonkaman
Copy link

@tallguyjenks
Copy link
Owner Author

well for the Darwin page, it says the -maxdepth option the way im using it is valid, i quoted the variable feeding it, so try again and see if the latest push works

@jhonkaman
Copy link

Ok I think that worked. This is what I see now. How do I get the sample deck?

No decks were found, please make a new deck
using : as a delimiter in a .csv file in
the .local/share/flash directory.

An example of a card:
Math:What is the square root of 4?:2:0

@tallguyjenks
Copy link
Owner Author

thats good, but not the answer that should have been displayed, can you ls -la the contents of the ~/Application Support/flash directory?

i pushed some more changes to try after that too

@jhonkaman
Copy link

jhonkaman commented Apr 27, 2020

ls -la for ~/Library/Application Support/flash (I had to add in the Library part to get the right path):

total 0
drwxr-xr-x   4 Javier  staff   128B Apr 27 13:19 ./
drwx------+ 88 Javier  staff   2.8K Apr 27 13:19 ../
-rw-r--r--   1 Javier  staff     0B Apr 27 13:19 .highscore
-rw-r--r--   1 Javier  staff     0B Apr 27 13:19 .reviews

@tallguyjenks
Copy link
Owner Author

okay so its not making the example deck like it should, did you re-run the latest commit: 46deb03

@jhonkaman
Copy link

Yes, I'm still getting the same output from above.

@tallguyjenks
Copy link
Owner Author

i think it may have been the use of variables in the brace expansion for OSx... maybe. moved some things around try latest build

@jhonkaman
Copy link

I tried the latest build, but I'm still getting the same output.

@tallguyjenks
Copy link
Owner Author

okay i have 2 more ideas for this issue. can you first test and anywhere in your system run touch test.csv and see if it is in fact creating the file

@jhonkaman
Copy link

touch test.csv does create a file.

@tallguyjenks
Copy link
Owner Author

tallguyjenks commented Apr 29, 2020

@jhonkaman alright i removed the brace expansion and just made individual touch commands, try build c8391d9

@jhonkaman
Copy link

Now I'm getting the previous error again:

find: illegal option -- m
usage: find [-H | -L | -P] [-EXdsx] [-f path] path ... [expression]
       find [-H | -L | -P] [-EXdsx] -f path [path ...] [expression]

No decks were found, please make a new deck
using : as a delimiter in a .csv file in
the /Users/Javier/Library/Application Support/flash directory.

An example of a card:
Math:What is the square root of 4?:2:0

@tallguyjenks
Copy link
Owner Author

god, mac is such a pain. try 9ab26d5

@jhonkaman
Copy link

I'm still getting the same output. I think this might be the issue: https://stackoverflow.com/questions/17548854/difference-between-mac-find-and-linux-find

@tallguyjenks
Copy link
Owner Author

@jhonkaman alright, i added the find path, lets see if the latest build works 0b1f60a

@jhonkaman
Copy link

Ok, that got rid of the error. Still getting this part:

No decks were found, please make a new deck
using : as a delimiter in a .csv file in
the /Users/Javier/Library/Application Support/flash directory.

An example of a card:
Math:What is the square root of 4?:2:0

If I had to guess, it looks like you're checking to see if any decks exist on line 124 and returning to the starting directory if there aren't any decks. I think you should add the touch command there from your setup() function to create the example deck.

@tallguyjenks
Copy link
Owner Author

first, can you remove the entire directory and all its contents and run it fresh? the script is meant to work on the first go, if it makes the directory but not the deck then it will be stuck until a deck is made, try a clean slate one more time

@tallguyjenks
Copy link
Owner Author

with build
5c717b1

@jhonkaman
Copy link

Ok, tried it. Output:

No /Users/Javier/Library/Application Support/flash directory, make it? Y/N
y
touch: Support/flash/deck.csv: No such file or directory
touch: Support/flash/.highscore: No such file or directory
touch: Support/flash/.reviews: No such file or directory

No decks were found, please make a new deck
using : as a delimiter in a .csv file in
the /Users/Javier/Library/Application Support/flash directory.

An example of a card:
Math:What is the square root of 4?:2:0

@tallguyjenks
Copy link
Owner Author

Progress! i get it now, i think i need to escape the spaces in the double quoted strings, new build coming in one sec.... okay: 23baa6d

@jhonkaman
Copy link

Ok, now I'm getting two things:

No /Users/Javier/Library/Application\ Support/flash directory, make it? Y/N
y
mkdir: /Users/Javier/Library/Application\ Support: No such file or directory
/usr/local/bin/flash: line 121: cd: /Users/Javier/Library/Application\ Support/flash: No such file or directory
touch: /Users/Javier/Library/Application\ Support/flash/.highscore: No such file or directory
touch: /Users/Javier/Library/Application\ Support/flash/.reviews: No such file or directory
/usr/local/bin/flash: line 147: shuf: command not found

And:

\e[1mCards Reviewed:\e[1m	0
cat: /Users/Javier/Library/Application\ Support/flash/.highscore: No such file or directory
    \e[1mHigh Score:\e[1m	
awk: can't open file /Users/Javier/Library/Application\ Support/flash/.reviews
 source line number 1
    \e[1mAvg review:\e[1m	

Category:
        
Question:

Also it says .//test.csv on the actual flashcard screen:
Screen Shot 2020-05-02 at 1 14 04 PM

@jhonkaman
Copy link

I installed coreutils and tried the latest version, but got this error:

No HOME/Library/Application Support/flash directory, make it? Y/N
y
mkdir: HOME/Library/Application Support: No such file or directory
/usr/local/bin/flash: line 133: cd: HOME/Library/Application Support/flash: No such file or directory

@tallguyjenks
Copy link
Owner Author

@jhonkaman found it, it was a missing $ for the mac file path $HOME variable. and fixed another issue with the installation of coreutils shuf is installed as gshuf so i alias it in the script to retain functionality. test latest build

@jhonkaman
Copy link

Latest output:

No /Users/Javier/Library/Application Support/flash directory, make it? Y/N
y
touch: Support/flash/deck.csv: No such file or directory
touch: Support/flash/.highscore: No such file or directory
touch: Support/flash/.reviews: No such file or directory

@jhonkaman
Copy link

Also, does it matter if my shell is zsh?

@tallguyjenks
Copy link
Owner Author

yeah it matters, zsh breaks scripts with bashisms im not sure if thats whats happening or not though..

@jsnal
Copy link
Contributor

jsnal commented May 14, 2020

It shouldn't matter if your shell is zsh. Your script includes a shebang line at the top, so as long as you're invoking the file using source or ./ it will use the interpreter in the shebang line. In this case, it's in your path so it's essentially sourcing it.

Seems like the way deck.csv (and the other two) is being appended to $DIR could be the problem. However, it seems right to me. Maybe it works differently when concatenating strings with spaces?

@tallguyjenks
Copy link
Owner Author

@jsnal thats what im thinking and im unsure about how to make it work at this point, i tried to escape the space but IIRC that breaks the file path

@jsnal
Copy link
Contributor

jsnal commented May 14, 2020

Alright so I did some testing and it seems like if you remove eval from your touch statement it works as expected. I tested it with Linux and macOS 10.14.6 (Mojave) and it seems to install everything fine. Why are you using eval there?

@tallguyjenks
Copy link
Owner Author

tallguyjenks commented May 14, 2020 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants