-
Notifications
You must be signed in to change notification settings - Fork 0
/
.functions
104 lines (92 loc) · 2.68 KB
/
.functions
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
104
# Better zoxide integration with fzf
function z() {
[ $# -gt 0 ] && _z "$*" && return
cd "$(_z -l 2>&1 | fzf-tmux +s --tac --query "$*" | sed 's/^[0-9,.]* *//')"
}
# Show chrome history
function ch() {
local cols sep google_history open
cols=$(( COLUMNS / 3 ))
sep='{::}'
google_history=$(wslpath "$(wslvar USERPROFILE)")/AppData/local/google/chrome/User\ Data/Default/History
cp -f "$google_history" /tmp/h
sqlite3 -separator $sep /tmp/h \
"select substr(title, 1, $cols), url
from urls order by last_visit_time desc" |
awk -F $sep '{printf "%-'$cols's \x1b[36m%s\x1b[m\n", $1, $2}' |
fzf --ansi --multi | sed 's#.*\(https*://\)#\1#' | xargs echo
}
# Git clone with chrome history
function git-clone() {
local url
url=ch | xargs echo
git clone "$(ch | xargs echo).git"
}
# Start service
function ss(){
sudo service $1 start
}
# Open wsl files in windows file explorer
# function open
# {
# explorer.exe `wslpath -w "$1"`
# }
# Search man pages FIX
function find-man() {
man -k | fzf -q "$1" --prompt='man> ' --preview $'echo {} | tr -d \'()\' | awk \'{printf "%s ", $2} {print $1}\' | xargs -r man | col -bx | bat -l man -p --color always' | tr -d '()' | awk '{printf "%s ", $2} {print $1}' | xargs -r man
}
# Git add and commit alias
function gac() {
git add .
if [ "$1" != "" ]
then
git commit -m "$1"
else
cz
# echo "Stop being dumb! \n Take a break, get a coffee and run the alias again but this time with a commit message."
fi
}
# Git worktree add
function gwa() {
if [ "$1" != "" ]
then
git worktree add ../$(echo "$1" | sed "s./.--.g") $2 -b $1 &&
echo "$2" | grep -qv "^origin/" || git branch --unset-upstream $1;
else
echo "0 parameters were provided.- \n $1 = branch \n $2 = options extra parameters"
fi
}
#Git worktree remove and delete branch
function gwr() {
WORKTREE_PATH=../$(echo "$1" | sed "s./.--.g")
git worktree remove $WORKTREE_PATH $2
if [ "$?" = 0 ]
then
echo "Worktree ${WORKTREE_PATH} successfully removed."
git branch -d $1
else
echo "Worktree ${WORKTREE_PATH} returned the following error code. \n Error code: $?"
fi
}
# Run commands in cmd
function cmd() {
CMD=$1
shift;
ARGS=$@
WIN_PWD=`wslpath -w "$(pwd)"`
#cmd.exe /c "pushd ${WIN_PWD} && ${CMD} ${ARGS}"
pushd /mnt/c >/dev/null
cmd.exe /C "pushd ${WIN_PWD} && ${CMD} ${ARGS}"
popd >/dev/null
}
# Search aliases with fzf
function fzf_alias() {
local selection
if selection=$(alias | fzf --query="$BUFFER" | sed -re 's/=.+$/ /'); then
BUFFER=$selection
fi
}
# Paste the ouput of the last command
function insert-last-command-output() {
LBUFFER+="$(eval $history[$((HISTCMD-1))])"
}