Skip to content

Instantly share code, notes, and snippets.

@speed-of-light
Forked from fajrif/gist:1265203
Last active December 21, 2015 10:08
Show Gist options
  • Select an option

  • Save speed-of-light/6289742 to your computer and use it in GitHub Desktop.

Select an option

Save speed-of-light/6289742 to your computer and use it in GitHub Desktop.
shell string manipulation
function gcst(){
# $1: repo path
# $2: tag-name
git clone $1
cd ${$1%%.*}
git tag -l
git checkout $2
git branch -D master
git checkout -b master
}
Given:
foo=/tmp/my.dir/filename.tar.gz
We can use these expressions:
path = ${foo%/*}
To get: /tmp/my.dir (like dirname)
file = ${foo##*/}
To get: filename.tar.gz (like basename)
base = ${file%%.*}
To get: filename
ext = ${file#*.}
To get: tar.gz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment