-
Notifications
You must be signed in to change notification settings - Fork 0
/
dot_bashrc
91 lines (79 loc) · 2.67 KB
/
dot_bashrc
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# Sample .bashrc for SuSE Linux
# Copyright (c) SuSE GmbH Nuernberg
# There are 3 different types of shells in bash: the login shell, normal shell
# and interactive shell. Login shells read ~/.profile and interactive shells
# read ~/.bashrc; in our setup, /etc/profile sources ~/.bashrc - thus all
# settings made here will also take effect in a login shell.
#
# NOTE: It is recommended to make language settings in ~/.profile rather than
# here, since multilingual X sessions would not work properly if LANG is over-
# ridden in every subshell.
# Some applications read the EDITOR variable to determine your favourite text
# editor. So uncomment the line below and enter the editor of your choice :-)
export EDITOR=vim
#export EDITOR=/usr/bin/mcedit
# For some news readers it makes sense to specify the NEWSSERVER variable here
#export NEWSSERVER=your.news.server
# If you want to use a Palm device with Linux, uncomment the two lines below.
# For some (older) Palm Pilots, you might need to set a lower baud rate
# e.g. 57600 or 38400; lowest is 9600 (very slow!)
#
#export PILOTPORT=/dev/pilot
#export PILOTRATE=115200
test -s ~/.alias && . ~/.alias || true
# Don't execute history commands directly, just place them on the command line
shopt -s histverify
# Override the cd builtin to do some nice things
function cd
{
# If no arguments (change to ~)
if [[ $# -eq 0 ]]
then
# If we are in a repo and we are not already in the root change to the repo root
local repo="$(git rev-parse --show-toplevel 2>/dev/null)"
if [[ -n "$repo" && "$PWD" != "$repo" ]]
then
builtin cd "$repo"
else
builtin cd "$@"
fi
else
builtin cd "$@"
fi
if [[ $? -eq 0 ]]
then
# Print last commit message if we come from outside a git repo
if git rev-parse --show-toplevel &>/dev/null
then
if ! [[ "$OLDPWD" == "$(git rev-parse --show-toplevel)"* ]]
then
echo "Last local commit:"
git log -1
fi
fi
fi
}
function mkcd
{
mkdir -p "$@" && cd "$@"
}
# Open vim pointing at a specific line in the file
function vim
{
# If no arguments, more than one argument, or the filename
# does not contain a line number, pass through to VIM
if [[ $# -eq 0 || $# -gt 1 || ! "$1" =~ ^.*:[0-9]+$ ]]
then
command vim "$@"
else
lineno="${1##*:}"
filename="${1%:"$lineno"}"
command vim +"$lineno" -c "normal zt" "$filename"
fi
}
# NPM stuff
NPM_PACKAGES="${HOME}/.local/npm-packages"
export PATH="$PATH:$NPM_PACKAGES/bin"
# Preserve MANPATH if you already defined it somewhere in your config.
# Otherwise, fall back to `manpath` so we can inherit from `/etc/manpath`.
export MANPATH="${MANPATH-$(manpath)}:$NPM_PACKAGES/share/man"