-
Notifications
You must be signed in to change notification settings - Fork 0
/
.bashnbrc
41 lines (33 loc) · 1.34 KB
/
.bashnbrc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# Startup commands for bash notebooks
bind "set show-mode-in-prompt off" # Turn off showing the vi mode in prompt, which clutters up the output
# Function for embedding a link to a file in the companion repo
# Replaces a filename in curly braces with a link to the file in the repo @ HEAD
# Requires the variable $GITHUB_URL to be set with an https url to the repository
embed-repo-link() {
file=$(echo $1 | awk -F '{|}' '{print $2}') # get filename that was in curly braces
link="$GITHUB_URL/tree/$(git rev-parse HEAD)/$file"
echo $1 | sed "s~{[^}]*}~[\`$file\`]($link)~g" | displayMD
}
# Function to show a file as markdown code
# First argument is the type of code to syntax highlight, second is the file to show
show-code() {
echo "\`\`\`$1
$(cat $2)
\`\`\`" | displayMD
}
# git checkpoint: checks out the next commit, failing if this would change the working tree
git-checkpoint() {
next_commit="$(git rev-list --topo-order HEAD...main | tail -1)"
git add -A
if ! git diff --quiet $next_commit; then
echo "git-checkpoint error - differences found with next commit:"
git diff $next_commit
git restore --staged *
return 1
fi
git switch -d $next_commit
}
# Alias for colored ls
alias ls="gls --color=always"
# Get the git object ID of an empty tree, useful for diffing files in the first commit
EMPTY_TREE=$(git hash-object -t tree /dev/null)