-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.shell_functions
55 lines (46 loc) · 1.01 KB
/
.shell_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
## diff folders
function dirdiff()
{
# Shell-escape each path:
DIR1=$(printf '%q' "$1"); shift
DIR2=$(printf '%q' "$1"); shift
vim $@ -c "DirDiff $DIR1 $DIR2"
}
## fd - cd to selected directory
fd() {
local dir
dir=$(find ${1:-.} -path '*/\.*' -prune \
-o -type d -print 2> /dev/null | fzf +m) &&
cd "$dir"
}
## run R script with echo
rsc() {
Rscript -e 'source(file("stdin"), echo=TRUE, spaced=TRUE)'< ${1}
}
## remove lines from second file that exist in the first file
remove-lines() (
remove_lines="$1"
all_lines="$2"
grep -Fvxf "$remove_lines" "$all_lines"
)
## set alias if exist
alias_if() (
if (( $+commands[$2] )); then
alias "$1"="$2"
echo "alias $1"="$2"
else
if (( $+commands[$1] )); then
echo "IS HERE: $1"
else
echo "NOT HERE: $1"
fi
fi
)
## preserve mtime on a edited file
vim_preserve_time () {
for file in "$@"; do
local mtime=$(stat -c %y "$file")
vim "$file"
touch -d "$mtime" "$file"
done
}