-
Notifications
You must be signed in to change notification settings - Fork 8
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
Clean up bash idioms, use modern interpolation style #11
Open
obscurerichard
wants to merge
2
commits into
rolfschr:master
Choose a base branch
from
obscurerichard:clean-bash
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,25 @@ | ||
#!/bin/bash | ||
#!/usr/bin/env bash | ||
# alias file for ledger from Getting Started With Ledger | ||
# https://github.com/rolfschr/GSWL-ecosystem.git | ||
# | ||
# Source this to activate the variables and functions within: | ||
# source ./alias | ||
|
||
# Debug this with: | ||
# DEBUG=true bash ./alias | ||
# It will echo commands and line numbers. | ||
DEBUG=${DEBUG:-false} | ||
|
||
# When debugging use bash unofficial strict mode | ||
# See http://redsymbol.net/articles/unofficial-bash-strict-mode/ | ||
$DEBUG && set -euo pipefail | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we always set |
||
|
||
# Thanks https://stackoverflow.com/a/17805088 | ||
$DEBUG && export PS4='${LINENO}: ' && set -x | ||
|
||
# http://stackoverflow.com/questions/59895/can-a-bash-script-tell-what-directory-its-stored-in | ||
LEDGER_ECOSYSTEM_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" | ||
|
||
LEDGER_ECOSYSTEM_DIR=$(dirname "$_") # needed for later | ||
if [[ "$_" == "" && ! -z $BASH ]] ; then | ||
LEDGER_ECOSYSTEM_DIR=$(dirname "$BASH_SOURCE") | ||
fi | ||
|
||
# This is the main command to invoke Ledger. | ||
# --strict : Warn if account, tag or commodity is unknown. | ||
|
@@ -28,19 +44,19 @@ alias ledconv="${LEDGER_ECOSYSTEM_DIR}/convert.py" | |
# When the latter are named consistently (ex:"apr2044_bank1.csv, | ||
# may2044_bank1.csv") one can use simple aliases to always convert the latest | ||
# CSV files. (Assuming monthly updates in this case.) | ||
THIS_AMN=$(date +'%b' | tr '[:upper:]' '[:lower:]') # Abreviated Month Name, e.g. "apr" | ||
export THIS_AMN=$(date +'%b' | tr '[:upper:]' '[:lower:]') # Abreviated Month Name, e.g. "apr" | ||
|
||
GNU_DATE=$(date -d 'last year' 2>/dev/null) | ||
GNU_DATE=$(date -d 'last year' 2>/dev/null) || true | ||
if [[ "$GNU_DATE" == "" ]]; then | ||
LAST_AMN=$(date -v-1m +'%b' | tr '[:upper:]' '[:lower:]') # "apr" | ||
LAST_YEAR=$(date -v-1y +'%Y') # "2044" | ||
FST_DOM_6MONTHS_AGO=`date -v-6m +"%Y/%m/01"` | ||
FST_DOM_12MONTHS_AGO=`date -v-12m +"%Y/%m/01"` | ||
FST_DOM_6MONTHS_AGO=$(date -v-6m +"%Y/%m/01") | ||
FST_DOM_12MONTHS_AGO=$(date -v-12m +"%Y/%m/01") | ||
else | ||
LAST_AMN=$(date +'%b' -d 'last month' | tr '[:upper:]' '[:lower:]') # "apr" | ||
LAST_YEAR=$(date +'%Y' -d 'last year') # "2044" | ||
FST_DOM_6MONTHS_AGO=`date +"%Y/%m/01" -d "6 months ago"` | ||
FST_DOM_12MONTHS_AGO=`date +"%Y/%m/01" -d "12 months ago"` | ||
FST_DOM_6MONTHS_AGO=$(date +"%Y/%m/01" -d "6 months ago") | ||
FST_DOM_12MONTHS_AGO=$(date +"%Y/%m/01" -d "12 months ago") | ||
fi | ||
|
||
|
||
|
@@ -50,6 +66,7 @@ if [[ "$LAST_AMN" == "dec" ]]; then | |
LAST_AMN_AND_YEAR="${LAST_AMN}${LAST_YEAR}" | ||
fi | ||
# First Day Of Month x Months Ago (may be used for specific Ledger reports) | ||
export THIS_YEAR LAST_AMN LAST_YEAR LAST_AMN_AND_YEAR FST_DOM_6MONTHS_AGO FST_DOM_12MONTHS_AGO | ||
|
||
function ledxact () { | ||
FILE=misc.tmp.txt | ||
|
@@ -140,4 +157,4 @@ alias lmmake="cat \$(listTmpFiles) > $ATMPFILE && ledger $LEDGERARGS -f $ATMPFIL | |
alias lmclean="rm ./tmp/*" | ||
|
||
# Source this file in the current working directory | ||
source alias.local 2>/dev/null | ||
[[ -f alias.local ]] && source alias.local || true |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍