-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbash_aliases
More file actions
177 lines (157 loc) · 5.16 KB
/
Copy pathbash_aliases
File metadata and controls
177 lines (157 loc) · 5.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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
# -*- mode: shell-script ; coding: utf-8 ; -*-
# .bash_aliases - bash and zsh aliases
: "start .bash_aliases"
###
### hooks
###
function __cdhook_screen_title_pwd {
test "$TERM" = screen || return
test "$CDHOOK_SCREEN_TITLE" = off && return
local title gitdir="$(git rev-parse --show-superproject-working-tree --show-toplevel 2>/dev/null)"
test -n "$gitdir" && title="git:${gitdir/*\//}" || title="${PWD/*\//}"
test "$PWD" = "$HOME" && title="~"
test "$PWD" = "/" && title="/"
screen -X title "$title"
}
###
### Basics
###
if is_darwin ; then
if exists gls ; then
alias ls='gls --color=auto -F'
# dircolors process is following
else
alias ls='ls -FG'
fi
alias ql='qlmanage -p 2>/dev/null'
alias imgdim='sips -g pixelHeight -g pixelWidth $1'
alias pbtee='cat | pbcopy ; sleep 1 ; pbpaste'
alias pwdcopy='echo -n $(pwd)/ | pbcopy'
fi
if is_linux ; then
alias ls='ls --color=auto -F'
alias crontab='crontab -i'
fi
if is_kde ; then
source_if_readable ~/.bash_aliases_kde
fi
if is_cygwin ; then
alias ls='ls --color -F --show-control-chars'
source_if_readable ~/.bash_aliases_cygwin
fi
if is_cursor_local || is_cursor_codespaces ; then
alias code='echo "dispatch cursor cli ✨" ; cursor'
fi
if exists dircolors ; then
if [ -f ~/.dir_colors ] ; then
eval "$(dircolors -b ~/.dir_colors)"
else
eval "$(dircolors -b)"
fi
fi
alias grep='grep --color=auto'
alias en='env LANG=C '
alias mv='mv -i'
alias tree='tree -NC' # tree -N for showing multibytes character
alias lv='lv -c'
alias less='less -R'
exists hub && alias git=hub
exists colordiff && alias diff=colordiff
alias od='od -tx1z -Ax -v' # http://d.hatena.ne.jp/maji-KY/20110718/1310985449
exists highlight && alias hl=highlight # http://search.cpan.org/dist/App-highlight/
# http://suzuki.tdiary.net/20140516.html#p01
if [ -f /usr/local/bin/highlight ] ; then
alias syntaxhi=/usr/local/bin/highlight
fi
if exists eza ; then
# The prefix 'e' in commands represents 'extended' or 'eza' (a modern ls replacement),
# indicating enhanced functionality over standard commands.
alias els='eza -F --color=auto --git '
alias etree='eza -F --color=auto --git --tree '
# eza is a modern replacement for ls, providing better defaults and features.
alias ls='eza -F --color=auto --git '
alias lsrepo='eza -F --color=auto --git-repos --long --header '
fi
if exists gemini ; then
alias gprompt='gemini --prompt'
GP_PAGER="${GP_PAGER:-}"
# Use a wrapper function to avoid array expansion issues in different shells.
if [ -z "$GP_PAGER" ] ; then
if exists bat ; then
GP_PAGER_CMD=(bat --plain --color=auto --language=markdown)
else
GP_PAGER_CMD=("${PAGER:-less}")
fi
else
# Split GP_PAGER string into array by spaces (simple heuristic)
# If the user provided a custom command with arguments, they can set GP_PAGER_CMD manually.
GP_PAGER_CMD=($GP_PAGER)
fi
__gpager() {
# Pipe stdin to the configured pager command safely.
# Use command builtin to avoid aliases.
if [ ${#GP_PAGER_CMD[@]} -eq 0 ]; then
cat
return
fi
command "${GP_PAGER_CMD[0]}" "${GP_PAGER_CMD[@]:1}"
local pager_status=$?
if [ $pager_status -ne 0 ]; then
cat
fi
return $pager_status
}
function gsearch {
[ -z "${1:?Usage: gsearch <query>}" ] && return 1
local prompt="「${1}」について調べて下さい"
echo "💬 $prompt"
gprompt "$prompt" | __gpager
}
function geman {
[ -z "${1:?Usage: geman <command>}" ] && return 1
local prompt="\"${1}\" コマンドの使い方を教えてください"
echo "💬 $prompt"
gprompt "$prompt" | __gpager
}
fi
###
### JavaScript / TypeScript
###
# see: https://zenn.dev/mizchi/articles/experimental-node-typescript
# Simple version without arrays to avoid shell compatibility issues
alias nodets='node --experimental-strip-types --experimental-transform-types --experimental-detect-module --no-warnings=ExperimentalWarning'
###
### Perl
###
alias system-perldoc='/usr/bin/perldoc'
alias system-perl='/usr/bin/perl'
alias perl-deparse='perl -MO=Deparse '
alias perl-installed-modules="perl -MExtUtils::Installed -E 'say(\$_) for ExtUtils::Installed->new->modules'"
alias uri_unescape='perl -MURI::Escape=uri_unescape -E "say uri_unescape(join q/ /, @ARGV)" '
alias uri_escape='perl -MURI::Escape=uri_escape -E "say uri_escape(join q/ /, @ARGV)" '
###
### path
###
function pathctl {
local subcommand="${1:-}"
shift || true
case "$subcommand" in
view)
echo "PATH=$PATH"
;;
list)
echo "$PATH" | tr : '\n'
;;
uniq)
PATH=$( perl -e 'print join ":", grep { !$seen{$_}++ } split /:/, $ENV{PATH}' )
;;
exist)
perl -e '$p = shift; exit($ENV{PATH} =~ /(?<=:|\A)\Q$p\E(?=:|\z)/ ? 0 : 1)' "$1"
;;
*)
echo "Usage: pathctl [view|list|uniq|exist]"
;;
esac
}
ALIASES_DONE=1
: "end .bash_aliases"