-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbashrc_symlink
103 lines (97 loc) · 2.58 KB
/
bashrc_symlink
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
92
93
94
95
96
97
98
99
100
101
102
103
#!/bin/bash
export TERM=screen-256color
alias reload="source ~/.bashrc"
alias tmux-work="~/workspace/dotfiles/tmux/tmux-work.sh"
alias fixmes="grep --exclude \"*.sw?\" -r \"FIXME\" ."
alias emacs="emacs -nw $1"
export CLICOLOR=1
export LSCOLORS=ExFxBxDxCxegedabagacad
login() {
SESSION_ID=`pgrep ssh-agent`
if [ "$?" != "0" ]; then
eval `ssh-agent -s`
fi
ID_RSA_KEY=`ssh-add -l | grep id_rsa`
if [ "$?" != "0" ]; then
ssh-add ~/.ssh/id_rsa
fi
}
rename-all() {
if [ "$1" = "" ]; then
echo "Specify original and new extension"
return
fi
eval "for f in *.$1; do mv -- \"\$f\" \"\${f%.$1}.$2\"; done"
}
###
# jump aliases, courtesy Jeroen Janssens:
# http://jeroenjanssens.com/2013/08/16/quickly-navigate-your-filesystem-from-the-command-line.html
###
export MARKPATH=$HOME/.marks
function jump {
if [ "$1" == "" ]; then
m=`ls ~/.marks | fzf`
if [ "$m" == "" ]; then
echo "Please specify a mark"
return 1
fi
pushd . > /dev/null
cd -P "$MARKPATH/$m" 2>/dev/null || echo "No such mark: $p"
return 0
fi
pushd . > /dev/null
cd -P "$MARKPATH/$1" 2>/dev/null || echo "No such mark: $1"
}
function mark {
mkdir -p "$MARKPATH"; ln -sf "$(pwd)" "$MARKPATH/$1"
}
function unmark {
rm -i "$MARKPATH/$1"
}
function marks {
mkdir -p "$MARKPATH"
ls -l "$MARKPATH" | sed 's/\s\s*/ /g' | cut -d' ' -f9- | sed 's/ -/\t-/g' && echo
}
_completemarks() {
local curw=${COMP_WORDS[COMP_CWORD]}
local wordlist=$(find $MARKPATH -type l -printf "%f\n")
COMPREPLY=($(compgen -W '${wordlist[@]}' -- "$curw"))
return 0
}
if [ "$(uname)" == "Darwin" ]; then
function marks {
\ls -l "$MARKPATH" | tail -n +2 | sed 's/ / /g' | cut -d' ' -f9- | awk -F ' -> ' '{printf "%-10s -> %s\n", $1, $2}'
}
_completemarks() {
local curw=${COMP_WORDS[COMP_CWORD]}
local wordlist=$(find $MARKPATH -type l | xargs -n1 basename)
COMPREPLY=($(compgen -W '${wordlist[@]}' -- "$curw"))
return 0
}
fi
complete -F _completemarks jump unmark
alias j="jump"
function rco {
r="$1"
if [ "$1" == "" ]; then
r=`git remote | fzf`
fi
if [ $? -eq 0 ]; then
echo "Fetching from upstream $r..."
git fetch "$r" --prune
b="$2"
if [ "$2" == "" ]; then
b=`git branch -r -l "$r/*" | fzf`
fi
if [ $? -eq 0 ]; then
remote_name=`echo "$b" | awk '{bn = index($0, "/"); print substr($0, bn+1);}'`
git checkout -b "$remote_name" "$r/$remote_name"
fi
fi
}
function withenv {
set -o allexport;
source .env;
set +o allexport;
"${@:1}";
}