style update and new post

This commit is contained in:
Micah Cowell 2016-05-02 21:20:27 -07:00
parent 02d23a56fb
commit cf93e20294
4 changed files with 92 additions and 6 deletions

View File

@ -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.

View File

@ -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})"
<hr class="codebreak">
$ ./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.
<h1 id="the-good-part">Using Strings in Arguments</h1>
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"
<hr class="codebreak">
$ ./spotify-now "%artist - %title"
Kendrick Lamar - To Pimp A Butterfly
<br><br>
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.

View File

@ -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";

View File

@ -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;
}
}
}