diff --git a/_posts/2016-03-26-arch-linux.md b/_posts/2016-03-26-arch-linux.md index 0c6d742..23abe7c 100644 --- a/_posts/2016-03-26-arch-linux.md +++ b/_posts/2016-03-26-arch-linux.md @@ -4,7 +4,7 @@ title: Arch Linux is Cool --- -For most my computer life I have either used Windows 7 or Linux. Windows was great but once I finally decided to try Ubuntu I never went back. I tried out all sorts of Linux distros (ie. Elementary OS, Crunchbang, Linux Mint) but none of them seemed right for me. After doing some searching around and I came to the conclusion that I had to attempt the unthinkable, Arch Linux. +For most my life with computers I have either used Windows 7 or Linux. Windows was great but once I finally decided to try Ubuntu I never went back. I tried out all sorts of Linux distros (ie. Elementary OS, Crunchbang, Linux Mint) but none of them seemed right for me. After doing some searching around and I came to the conclusion that I had to attempt the unthinkable, Arch Linux. # About My Computer *Hardware*: The PC I mainly use is a desktop that I built a few years back with a Intel Core i5, Nvidia GTX 650ti, and 8 GB of RAM. diff --git a/_posts/2016-05-02-passing-args-in-bash.md b/_posts/2016-05-02-passing-args-in-bash.md new file mode 100644 index 0000000..a8b3134 --- /dev/null +++ b/_posts/2016-05-02-passing-args-in-bash.md @@ -0,0 +1,61 @@ +--- +layout: post +title: Passing Arguments in Shell Script +--- + +**TL;DR** Just skip to the [good part](#the-good-part) + +# Basic Arguments +The other day I started making this shell script program [spotify-now](https://github.com/getmicah/spotify-now), which gets information on the current Spotify song using the dbus message from the media player. When writing this script I wanted to be able to pass in parameters to the script from the command line using arguments. + +This is easy as all you have do is use the `${n}` variable to get the parameter (n being the position of the argument). With my script it looked something like this: + + + #!/bin/bash + # spotify-now + + getTitle () { + ... + } + + echo "$(getTitle ${1})" + +
+ + $ ./spotify-now title + How Much A Dollar Cost + +Although this solution is quick and easy, it's also very limiting in the parameters you can pass and made for some messy terminal commands. + +

Using Strings in Arguments

+When brainstorming for a better way to pass command line arguments I came across the `date` command. This unix program prints out the system's time and date information. What intrigued me about this command is how it took in a date string containing keywords such as the name of the month or what hour it was. + + $ date '+Date: %b %d' + Date: May 02 + +I decided to find a way to implement this into my script. Usually, something like this would be done with a language such as C or Python but I was determined to stay with a simple shell script seeing as though it was a small program and I didn't want to over complicate things. + +To do this sort of thing in shell script all you have to do is replace the keywords in the string argument with the data you want. You have to do this for each keyword and error checking can be tedious but really not much worse than doing in any other language. + + #!/bin/bash + # spotify-now + + getArtist () { + ... + } + getTitle () { + ... + } + + INFO="${1}" + INFO="${INFO//"%artist"/$(artist)}" + INFO="${INFO//"%title"/$(title)}" + echo "$INFO" + +
+ + $ ./spotify-now "%artist - %title" + Kendrick Lamar - To Pimp A Butterfly + +

+Of course all this code is on my [Github](https://github.com/getmicah/spotify-now) and please do fork it and make pull requests regarding any issues or improvements you may have with my code. diff --git a/_sass/_config.scss b/_sass/_config.scss index 1fb0c7f..6b0d1e3 100644 --- a/_sass/_config.scss +++ b/_sass/_config.scss @@ -1,7 +1,9 @@ // COLORS -$color-primary: #272727; -$color-background: #FFFFFF; +$color-fg: #272727; +$color-bg: #FFFFFF; +$color-grey: #EEEEEE; $color-link: #1A0DAB; +$color-code: #00FF00; // FONT $font-url: "https://fonts.googleapis.com/css?family=Ubuntu+Mono:400,700,400italic"; diff --git a/assets/css/main.scss b/assets/css/main.scss index 60cdaa2..f9c7063 100644 --- a/assets/css/main.scss +++ b/assets/css/main.scss @@ -5,8 +5,8 @@ @import "config"; body { - color: $color-primary; - background: $color-background; + color: $color-fg; + background: $color-bg; font-family: 'Inconsolata', ; font-size: 100%; font-weight: 400; @@ -114,7 +114,7 @@ ul { &__content { padding-top: 40px; h1 { - font-size: 1.2em; + font-size: 1.25em; font-weight: 700; margin-top: 30px; margin-bottom: 5px; @@ -161,6 +161,29 @@ ul { margin: auto; } } + code { + padding: 3px; + font-size: 0.9em; + border-radius: 3px; + background: $color-grey; + } + .highlight { + margin: 10px; + margin-bottom: 15px; + padding: 10px; + line-height: 1.5; + border-radius: 3px; + background: $color-fg; + code { + color: $color-code; + background: none; + } + } + .codebreak { + margin: 15px; + border: 0; + border-bottom: 1px dashed $color-fg; + } } }