-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions
81 lines (66 loc) · 1.54 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
# syntax: bash
# vim: set filetype=sh:
#
# Shell functions
#
case "$-" in
*i*) : ;; # interactive
*) return ;;
esac
#
# Must be an interactive shell
#
# ----- Functions common to sh and bash -----
# $1 = filename to convert to abs
abs_file()
{
local file="$1"
if [ -n "$(which ruby)" ] ; then
ruby -we 'require "pathname" ; puts Pathname.new(ARGV.shift).realpath' "${file}"
return
fi
file=$(cd $(dirname "${file}") && pwd)/$(basename "${file}")
echo "${file}"
}
resize_terminal()
{
local width="$1"
local height="$2"
local command="\033[8;${height};${width}t"
printf "${command}"
}
alias resize-terminal=resize_terminal
source_when_readable()
{
local _file
for _file in "$@" ; do
if [ -f "${_file}" -a -r "${_file}" ] ; then
. "${_file}"
fi
done
unset _file
}
# general aliases
alias ls='ls -CF'
alias r='fc -s'
if [ -x /usr/bin/parallel-ssh -a -z "$(which pssh)" ] ; then
alias pssh=parallel-ssh
alias pscp=parallel-scp
fi
if [ -z "$(which sgrep)" ] ; then
alias sgrep='rg --no-heading --line-number --with-filename'
fi
if [ -z "$(which sha256sum)" -a -n "$(which shasum)" ] ; then
alias sha256sum='shasum -a 256'
fi
# ----- other functions -----
source_when_readable ${HOME}/dotfiles/functions.d/functions.*
# ----- Fallback functions for non-bash shells -----
if ! type set_title >/dev/null 2>&1 ; then
# set terminal title
set_title()
{
local ansititle="\033]0;${1}\007"
echo -n "${ansititle}"
}
fi