-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path.zshrc.extra
More file actions
106 lines (90 loc) · 2.16 KB
/
.zshrc.extra
File metadata and controls
106 lines (90 loc) · 2.16 KB
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
105
function rg {
extra_args=()
if [ -t 0 ]; then
# If stdin is from the terminal, output in vimgrep
# (If stdin is _not_ from the terminal, we don't want to apply any custom formatting)
extra_args+="--vimgrep"
fi
# rg automatically turns off hyperlinks if stdout isn't connected to the terminal
command rg --hyperlink-format=default "${extra_args[@]}" "$@"
}
function fd {
command fd --hyperlink=auto "$@"
}
# TODO: use --hyperlink=auto once it supports that
function ls {
if [ -t 1 ]; then
# If stdout is connected to the terminal, output terminal hyperlinks
command eza --hyperlink "$@"
else
command eza "$@"
fi
}
alias ..="cd .."
alias ...="cd ../.."
alias ....="cd ../../.."
alias .....="cd ../../../.."
alias ......="cd ../../../../.."
function replace {
rg -l "$1" $3 | xargs sd "$1" "$2"
}
function xim {
extra_args="-p"
if [[ "$1" == "-k" ]]; then
shift
extra_args="-k"
fi
xargs nvim ${extra_args} "$@"
}
alias xkm="xim -k"
function fdim {
extra_args=""
if [[ "$1" == "-k" ]]; then
shift
extra_args="-k"
fi
fd "$@" | xim ${extra_args}
}
alias fdkm="fdim -k"
function rgim {
extra_args=""
if [[ "$1" == "-k" ]]; then
shift
extra_args="-k"
fi
# List all files with that search, and also search for that pattern within nvim
# Assumes the pattern is the first argument
rg -l "$@" | xim ${extra_args} "+/$1"
}
alias rgkm="rgim -k"
function extract {
# Extract all filenames at the start of the line from the input stream
sed -n 's/^\([a-zA-Z0-9_/.-]*\.[a-zA-Z0-9_/.-]*\).*$/\1/p' | sort -u
}
function pbim {
# Extract all files from the
pbpaste | extract | xim "$@"
}
alias pbkm="pbim -k"
function fzim {
# Get files to edit with fzf
fzf -m | xim "$@"
}
alias fzkm="fzim -k"
function conflicts {
git conflicts | xim "$@"
}
function unstaged {
git diff --name-only | xim "$@"
}
function staged {
git diff --name-only --staged | xim "$@"
}
function cam {
git a && git cm "$@"
}
function prune {
header="${1:-hz}"
git branch --list | rg -v "^[*+]|${header}" | xargs git branch -D
git remote prune origin | sed -n -E "/${header}/ s/.*(${header}.*)/\\1/p" | xargs git branch -D
}