mirror of
https://github.com/arcan1s/arcanis.me.git
synced 2025-07-15 06:05:47 +00:00
Move website to Jekyll now
This commit is contained in:
@ -10,7 +10,6 @@ title: About zshrc
|
||||
description: It is first paper in my blog (I think I need something here for tests =)). There are many similar articles, and I'll not be an exception. I just want to show my <code>.zshrc</code> and explain what it does and why it is needed. Also any comments or additions are welcome. It is a translated paper from Russian (<a href="http://archlinux.org.ru/forum/topic/12752/">original</a>).
|
||||
commentIssueId: 5
|
||||
---
|
||||
|
||||
<h3><a name="prepare" class="anchor" href="#prepare"><span class="octicon octicon-link"></span></a>Prepare</h2>
|
||||
<p align="justify">First install recommended minima:</p>
|
||||
<pre>pacman -Sy pkgfile zsh zsh-completions zsh-syntax-highlighting</pre>
|
||||
@ -41,8 +40,8 @@ bindkey '\e[6~' down-line-or-history # page-down</pre>
|
||||
<pre># autocomplete
|
||||
autoload -U compinit
|
||||
compinit
|
||||
zstyle ':completion:\*' insert-tab false
|
||||
zstyle ':completion:\*' max-errors 2</pre>
|
||||
zstyle ':completion:*' insert-tab false
|
||||
zstyle ':completion:*' max-errors 2</pre>
|
||||
<p align="justify">Full command autocomplete will be enabled. <code>insert-tab false</code> will enable autocomplete for <b>non-entered</b> commands. <code>max-errors</code> sets maximum number of errors that could be corrected.</p>
|
||||
|
||||
<p align="justify">Prompt:</p>
|
||||
@ -89,19 +88,19 @@ source /usr/share/doc/pkgfile/command-not-found.zsh</pre>
|
||||
<div class="codeblock"># highlighting
|
||||
source /usr/share/zsh/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
|
||||
ZSH_HIGHLIGHT_HIGHLIGHTERS=(main brackets pattern)
|
||||
\# brackets
|
||||
# brackets
|
||||
ZSH_HIGHLIGHT_STYLES[bracket-level-1]='fg=blue,bold'
|
||||
ZSH_HIGHLIGHT_STYLES[bracket-level-2]='fg=red,bold'
|
||||
ZSH_HIGHLIGHT_STYLES[bracket-level-3]='fg=yellow,bold'
|
||||
ZSH_HIGHLIGHT_STYLES[bracket-level-4]='fg=magenta,bold'
|
||||
\# cursor
|
||||
\#ZSH_HIGHLIGHT_STYLES[cursor]='bg=blue'
|
||||
\# main
|
||||
\# default
|
||||
# cursor
|
||||
#ZSH_HIGHLIGHT_STYLES[cursor]='bg=blue'
|
||||
# main
|
||||
# default
|
||||
ZSH_HIGHLIGHT_STYLES[default]='none'
|
||||
\# unknown
|
||||
# unknown
|
||||
ZSH_HIGHLIGHT_STYLES[unknown-token]='fg=red'
|
||||
\# command
|
||||
# command
|
||||
ZSH_HIGHLIGHT_STYLES[reserved-word]='fg=magenta,bold'
|
||||
ZSH_HIGHLIGHT_STYLES[alias]='fg=yellow,bold'
|
||||
ZSH_HIGHLIGHT_STYLES[builtin]='fg=green,bold'
|
||||
@ -112,31 +111,31 @@ ZSH_HIGHLIGHT_STYLES[commandseparator]='fg=yellow'
|
||||
ZSH_HIGHLIGHT_STYLES[hashed-command]='fg=green'
|
||||
ZSH_HIGHLIGHT_STYLES[single-hyphen-option]='fg=blue,bold'
|
||||
ZSH_HIGHLIGHT_STYLES[double-hyphen-option]='fg=blue,bold'
|
||||
\# path
|
||||
# path
|
||||
ZSH_HIGHLIGHT_STYLES[path]='fg=cyan,bold'
|
||||
ZSH_HIGHLIGHT_STYLES[path_prefix]='fg=cyan'
|
||||
ZSH_HIGHLIGHT_STYLES[path_approx]='fg=cyan'
|
||||
\# shell
|
||||
# shell
|
||||
ZSH_HIGHLIGHT_STYLES[globbing]='fg=cyan'
|
||||
ZSH_HIGHLIGHT_STYLES[history-expansion]='fg=blue'
|
||||
ZSH_HIGHLIGHT_STYLES[assign]='fg=magenta'
|
||||
ZSH_HIGHLIGHT_STYLES[dollar-double-quoted-argument]='fg=cyan'
|
||||
ZSH_HIGHLIGHT_STYLES[back-double-quoted-argument]='fg=cyan'
|
||||
ZSH_HIGHLIGHT_STYLES[back-quoted-argument]='fg=blue'
|
||||
\# quotes
|
||||
# quotes
|
||||
ZSH_HIGHLIGHT_STYLES[single-quoted-argument]='fg=yellow,underline'
|
||||
ZSH_HIGHLIGHT_STYLES[double-quoted-argument]='fg=yellow'
|
||||
\# pattern example
|
||||
\#ZSH_HIGHLIGHT_PATTERNS+=('rm -rf \*' 'fg=white,bold,bg=red')
|
||||
\# root example
|
||||
\#ZSH_HIGHLIGHT_STYLES[root]='bg=red'</div>
|
||||
<p align="justify">In first line highlighting is turned on. Next main, brackets and pattern highlighting are turned on. Patterns are set below (<code>rm -rf \*</code> in the example). Also <code>root</code> and <code>cursor</code> highlighting may be turned on. Colors syntax is understandable, <code>fg</code> is font color, <code>bg</code> is background color.</p>
|
||||
# pattern example
|
||||
#ZSH_HIGHLIGHT_PATTERNS+=('rm -rf *' 'fg=white,bold,bg=red')
|
||||
# root example
|
||||
#ZSH_HIGHLIGHT_STYLES[root]='bg=red'</div>
|
||||
<p align="justify">In first line highlighting is turned on. Next main, brackets and pattern highlighting are turned on. Patterns are set below (<code>rm -rf *</code> in the example). Also <code>root</code> and <code>cursor</code> highlighting may be turned on. Colors syntax is understandable, <code>fg</code> is font color, <code>bg</code> is background color.</p>
|
||||
|
||||
<h3><a name="prompt" class="anchor" href="#prompt"><span class="octicon octicon-link"></span></a>$PROMPT and $RPROMPT</h2>
|
||||
<p align="justify">The general idea is the use single <code>.zshrc</code> for root and normal user:</p>
|
||||
<div class="codeblock"># PROMPT && RPROMPT
|
||||
if [[ $EUID == 0 ]]; then
|
||||
\# [root@host dir]\#
|
||||
# [root@host dir]#
|
||||
PROMPT="%{$fg_bold[white]%}[%{$reset_color%}\
|
||||
%{$fg_bold[red]%}%n%{$reset_color%}\
|
||||
%{$fg_bold[white]%}@%{$reset_color%}\
|
||||
@ -144,7 +143,7 @@ if [[ $EUID == 0 ]]; then
|
||||
%{$fg_bold[yellow]%}%1/%{$reset_color%}\
|
||||
%{$fg_bold[white]%}]# %{$reset_color%}"
|
||||
else
|
||||
\# [user@host dir]$
|
||||
# [user@host dir]$
|
||||
PROMPT="%{$fg_bold[white]%}[%{$reset_color%}\
|
||||
%{$fg_bold[green]%}%n%{$reset_color%}\
|
||||
%{$fg_bold[white]%}@%{$reset_color%}\
|
||||
@ -213,21 +212,21 @@ $returncode\
|
||||
|
||||
<p align="justify">Here is the first group of aliases:</p>
|
||||
<div class="codeblock">## alias
|
||||
\# colored grep
|
||||
# colored grep
|
||||
alias grep='grep --colour=auto'
|
||||
\# change top to htop
|
||||
# change top to htop
|
||||
alias top='show_which top && htop'
|
||||
\# chromium with different proxy servers (i2p and tor included)
|
||||
# chromium with different proxy servers (i2p and tor included)
|
||||
alias chrommsu='show_which chrommsu && chromium --proxy-server=cache.msu:3128'
|
||||
alias chromtor='show_which chromtor && chromium --proxy-server="socks://localhost:9050" --incognito'
|
||||
alias chromi2p='show_which chromi2p && chromium --proxy-server="http=127.0.0.1:4444;https=127.0.0.1:4445" --incognito'
|
||||
\# human-readable df and du
|
||||
# human-readable df and du
|
||||
alias df='show_which df && df -k --print-type --human-readable'
|
||||
alias du='show_which du && du -k --total --human-readable'
|
||||
\# change less and zless to vimpager
|
||||
# change less and zless to vimpager
|
||||
alias less='vimpager'
|
||||
alias zless='vimpager'
|
||||
\# more interactive rm
|
||||
# more interactive rm
|
||||
alias rm='show_which rm && rm -I'</div>
|
||||
|
||||
<p align="justify">Here are ls aliases (see <a href="http://unixhelp.ed.ac.uk/CGI/man-cgi?ls">man ls</a>):</p>
|
||||
@ -282,7 +281,7 @@ alias -g dn="&> /dev/null &"</pre>
|
||||
<p align="justify">Here is a special function for <code>xrandr</code>:</p>
|
||||
|
||||
<div class="codeblock"># function to contorl xrandr
|
||||
\# EXAMPLE: projctl 1024x768
|
||||
# EXAMPLE: projctl 1024x768
|
||||
projctl () {
|
||||
if [ $1 ] ; then
|
||||
if [ $1 = "-h" ]; then
|
||||
@ -304,34 +303,34 @@ projctl () {
|
||||
|
||||
<p align="justify">Unfortunately I can not remember <code>tar</code> flags thus I use special functions:</p>
|
||||
<div class="codeblock"># function to extract archives
|
||||
\# EXAMPLE: unpack file
|
||||
# EXAMPLE: unpack file
|
||||
unpack () {
|
||||
if [[ -f $1 ]]; then
|
||||
case $1 in
|
||||
\*.tar.bz2) tar xjfv $1 ;;
|
||||
\*.tar.gz) tar xzfv $1 ;;
|
||||
\*.tar.xz) tar xvJf $1 ;;
|
||||
\*.bz2) bunzip2 $1 ;;
|
||||
\*.gz) gunzip $1 ;;
|
||||
\*.rar) unrar x $1 ;;
|
||||
\*.tar) tar xf $1 ;;
|
||||
\*.tbz) tar xjvf $1 ;;
|
||||
\*.tbz2) tar xjf $1 ;;
|
||||
\*.tgz) tar xzf $1 ;;
|
||||
\*.zip) unzip $1 ;;
|
||||
\*.Z) uncompress $1 ;;
|
||||
\*.7z) 7z x $1 ;;
|
||||
\*) echo "I don't know how to extract '$1'" ;;
|
||||
*.tar.bz2) tar xjfv $1 ;;
|
||||
*.tar.gz) tar xzfv $1 ;;
|
||||
*.tar.xz) tar xvJf $1 ;;
|
||||
*.bz2) bunzip2 $1 ;;
|
||||
*.gz) gunzip $1 ;;
|
||||
*.rar) unrar x $1 ;;
|
||||
*.tar) tar xf $1 ;;
|
||||
*.tbz) tar xjvf $1 ;;
|
||||
*.tbz2) tar xjf $1 ;;
|
||||
*.tgz) tar xzf $1 ;;
|
||||
*.zip) unzip $1 ;;
|
||||
*.Z) uncompress $1 ;;
|
||||
*.7z) 7z x $1 ;;
|
||||
*) echo "I don't know how to extract '$1'" ;;
|
||||
esac
|
||||
else
|
||||
case $1 in
|
||||
\*help) echo "Usage: unpack ARCHIVE_NAME" ;;
|
||||
\*) echo "'$1' is not a valid file" ;;
|
||||
*help) echo "Usage: unpack ARCHIVE_NAME" ;;
|
||||
*) echo "'$1' is not a valid file" ;;
|
||||
esac
|
||||
fi
|
||||
}
|
||||
\# function to create archives
|
||||
\# EXAMPLE: pack tar file
|
||||
# function to create archives
|
||||
# EXAMPLE: pack tar file
|
||||
pack () {
|
||||
if [ $1 ]; then
|
||||
case $1 in
|
||||
@ -345,8 +344,8 @@ pack () {
|
||||
tgz) tar czvf $2.tar.gz $2 ;;
|
||||
zip) zip -r $2.zip $2 ;;
|
||||
7z) 7z a $2.7z $2 ;;
|
||||
\*help) echo "Usage: pack TYPE FILES" ;;
|
||||
\*) echo "'$1' cannot be packed via pack()" ;;
|
||||
*help) echo "Usage: pack TYPE FILES" ;;
|
||||
*) echo "'$1' cannot be packed via pack()" ;;
|
||||
esac
|
||||
else
|
||||
echo "'$1' is not a valid file"
|
||||
@ -363,22 +362,22 @@ pack () {
|
||||
done
|
||||
if [[ $checksu == 0 ]]; then
|
||||
echo "Use 'su -', Luke"
|
||||
/usr/bin/su - $\*
|
||||
/usr/bin/su - $*
|
||||
else
|
||||
/usr/bin/su $\*
|
||||
/usr/bin/su $*
|
||||
fi
|
||||
}</div>
|
||||
|
||||
<p align="justify">Functions with automatic rehash after installing/removing packages are:</p>
|
||||
<div class="codeblock">pacman () {
|
||||
/usr/bin/sudo /usr/bin/pacman $\* && echo "$\*" | grep -q "S\\|R\\|U" && rehash
|
||||
/usr/bin/sudo /usr/bin/pacman $* && echo "$*" | grep -q "S\\|R\\|U" && rehash
|
||||
}
|
||||
yaourt () {
|
||||
/usr/bin/yaourt $\* && echo "$\*" | grep -q "S\\|R\\|U" && rehash
|
||||
/usr/bin/yaourt $* && echo "$*" | grep -q "S\\|R\\|U" && rehash
|
||||
}
|
||||
\# for testing repo
|
||||
# for testing repo
|
||||
yatest () {
|
||||
/usr/bin/yaourt --config /etc/pactest.conf $\* && echo "$\*" | grep -q "S\\|R\\|U" && rehash
|
||||
/usr/bin/yaourt --config /etc/pactest.conf $* && echo "$*" | grep -q "S\\|R\\|U" && rehash
|
||||
}</div>
|
||||
<p align="justify">But autocomplete for <code>yaourt -Ss</code> <a href="https://github.com/zsh-users/zsh-completions/pull/205">will require</a> root privileges.</p>
|
||||
|
||||
@ -388,9 +387,9 @@ yatest () {
|
||||
<p align="justify">Here are path, mask of new files, editor and pager:</p>
|
||||
<pre># path
|
||||
export PATH="$PATH:$HOME/.local/bin"
|
||||
\# umask
|
||||
# umask
|
||||
umask 022
|
||||
\# editor
|
||||
# editor
|
||||
export EDITOR="vim"
|
||||
export PAGER="vimpager"</pre>
|
||||
|
Reference in New Issue
Block a user