summaryrefslogtreecommitdiff
path: root/functions
diff options
context:
space:
mode:
authorache <ache@ache.one>2017-06-01 18:17:36 +0200
committerache <ache@ache.one>2017-06-01 18:17:36 +0200
commitd99af1cd72b3cd093964e4565785fab563379253 (patch)
tree36920a8dfeea33bde747c8a34c903a1bf41f79b8 /functions
Init config
Diffstat (limited to 'functions')
-rw-r--r--functions/co.fish1
-rw-r--r--functions/curl.fish1
-rw-r--r--functions/dd.fish1
-rw-r--r--functions/déco.fish1
-rw-r--r--functions/egrep.fish1
-rw-r--r--functions/fgrep.fish1
-rw-r--r--functions/fish_prompt.fish333
-rw-r--r--functions/freboot.fish1
-rw-r--r--functions/g++.fish1
-rw-r--r--functions/gcc.fish1
-rw-r--r--functions/gccW.fish1
-rw-r--r--functions/grep.fish1
-rw-r--r--functions/grepb.fish1
-rw-r--r--functions/indent.fish1
-rw-r--r--functions/inhib.fish1
-rw-r--r--functions/ip.fish1
-rw-r--r--functions/l.fish1
-rw-r--r--functions/ll.fish3
-rw-r--r--functions/ls.fish1
-rw-r--r--functions/man.fish10
-rw-r--r--functions/mkpause.fish1
-rw-r--r--functions/msf.fish1
-rw-r--r--functions/mv.fish1
-rw-r--r--functions/off.fish1
-rw-r--r--functions/pacman.fish1
-rw-r--r--functions/pass.fish1
-rw-r--r--functions/reboot.fish1
-rw-r--r--functions/rv.fish1
-rw-r--r--functions/scanner.fish1
-rw-r--r--functions/sec.fish2
-rw-r--r--functions/t.fish1
-rw-r--r--functions/td.fish1
-rw-r--r--functions/wgetqp.fish1
-rw-r--r--functions/ydx.fish1
34 files changed, 378 insertions, 0 deletions
diff --git a/functions/co.fish b/functions/co.fish
new file mode 100644
index 0000000..9d3c38f
--- /dev/null
+++ b/functions/co.fish
@@ -0,0 +1 @@
+alias co='sudo dhcpcd'
diff --git a/functions/curl.fish b/functions/curl.fish
new file mode 100644
index 0000000..8c7eb24
--- /dev/null
+++ b/functions/curl.fish
@@ -0,0 +1 @@
+alias curl='curl -s'
diff --git a/functions/dd.fish b/functions/dd.fish
new file mode 100644
index 0000000..cef610f
--- /dev/null
+++ b/functions/dd.fish
@@ -0,0 +1 @@
+alias dd='dd status=progress'
diff --git a/functions/déco.fish b/functions/déco.fish
new file mode 100644
index 0000000..7bd02e6
--- /dev/null
+++ b/functions/déco.fish
@@ -0,0 +1 @@
+alias déco='sudo pkill dhcpcd; sudo pkill wpa_supplicant;sudo ip route flush via all;sudo pkill ssh'
diff --git a/functions/egrep.fish b/functions/egrep.fish
new file mode 100644
index 0000000..271b6ce
--- /dev/null
+++ b/functions/egrep.fish
@@ -0,0 +1 @@
+alias egrep='egrep --color=auto'
diff --git a/functions/fgrep.fish b/functions/fgrep.fish
new file mode 100644
index 0000000..0468b6c
--- /dev/null
+++ b/functions/fgrep.fish
@@ -0,0 +1 @@
+alias fgrep='fgrep --color=auto'
diff --git a/functions/fish_prompt.fish b/functions/fish_prompt.fish
new file mode 100644
index 0000000..180359d
--- /dev/null
+++ b/functions/fish_prompt.fish
@@ -0,0 +1,333 @@
+
+# Set these options in your config.fish (if you want to :])
+#
+# set -g theme_display_user yes
+# set -g theme_hostname never
+# set -g theme_hostname always
+# set -g default_user your_normal_user
+
+
+
+# Backward compatibility
+#
+# Note: Do not depend on these behavior. These can be removed in anytime by the
+# author in the name of code readability.
+if set -q theme_hide_hostname
+ # Existing $theme_hostname will always override $theme_hide_hostname
+ if not set -q theme_hostname
+ if [ "theme_hide_hostname" = "yes" ]
+ set -g theme_hostname never
+ end
+ if [ "theme_hide_hostname" = "no" ]
+ set -g theme_hostname always
+ end
+ end
+end
+
+
+#
+# Segments functions
+#
+set -g current_bg NONE
+set -g segment_separator \uE0B0
+
+function prompt_segment -d "Function to draw a segment"
+ set -l bg
+ set -l fg
+ if [ -n "$argv[1]" ]
+ set bg $argv[1]
+ else
+ set bg normal
+ end
+ if [ -n "$argv[2]" ]
+ set fg $argv[2]
+ else
+ set fg normal
+ end
+ if [ "$current_bg" != 'NONE' -a "$argv[1]" != "$current_bg" ]
+ set_color -b $bg
+ set_color $current_bg
+ echo -n "$segment_separator "
+ set_color -b $bg
+ set_color $fg
+ else
+ set_color -b $bg
+ set_color $fg
+ echo -n " "
+ end
+ set current_bg $argv[1]
+ if [ -n "$argv[3]" ]
+ echo -n -s $argv[3] " "
+ end
+end
+
+function prompt_finish -d "Close open segments"
+ if [ -n $current_bg ]
+ set_color -b normal
+ set_color $current_bg
+ echo -n "$segment_separator "
+ end
+ set -g current_bg NONE
+end
+
+
+#
+# Components
+#
+function prompt_virtual_env -d "Display Python virtual environment"
+ if test "$VIRTUAL_ENV"
+ prompt_segment white black (basename $VIRTUAL_ENV)
+ end
+end
+
+
+function prompt_user -d "Display current user if different from $default_user"
+ set -l BG 444444
+ set -l FG BCBCBC
+
+ if [ "$theme_display_user" = "yes" ]
+ if [ "$USER" != "$default_user" -o -n "$SSH_CLIENT" ]
+ set USER (whoami)
+ get_hostname
+ if [ $HOSTNAME_PROMPT ]
+ set USER_PROMPT $USER@$HOSTNAME_PROMPT
+ else
+ set USER_PROMPT $USER
+ end
+ prompt_segment $BG $FG $USER_PROMPT
+ end
+ else
+ get_hostname
+ if [ $HOSTNAME_PROMPT ]
+ prompt_segment $BG $FG $HOSTNAME_PROMPT
+ end
+ end
+end
+
+function get_hostname -d "Set current hostname to prompt variable $HOSTNAME_PROMPT if connected via SSH"
+ set -g HOSTNAME_PROMPT ""
+ if [ "$theme_hostname" = "always" -o \( "$theme_hostname" != "never" -a -n "$SSH_CLIENT" \) ]
+ set -g HOSTNAME_PROMPT (hostname)
+ end
+end
+
+function prompt_shlv -d "Display level shell"
+ set pline ''
+ if [ "$VIMRUNTIME" != "" ]
+ set pline 'vim'
+ if [ "$SHLVL" -gt 3 ]
+ set pline 'vim:['$SHLVL']'
+ end
+ else
+ if [ "$SHLVL" -gt 2 ]
+ set pline '['$SHLVL']'
+ end
+ end
+ if [ $pline != '' ]
+ prompt_segment 8C8C8C black "$pline"
+ end
+end
+
+function prompt_todo -d "Display todo"
+ set all (todo | wc -l)
+ set chkd (todo checked | wc -l)
+ set td (math "$all-$chkd")
+
+ if [ $all -gt 0 ]
+ prompt_segment 5C5C5C blue "$td/$all"
+ end
+end
+
+
+
+
+
+function prompt_dir -d "Display the current directory"
+ prompt_segment 1C1C1C FFFFFF (prompt_pwd)
+end
+
+function git_status_summary -d "Deal with git status --porcelain"
+ awk '
+ BEGIN {
+ untracked=0;
+ unstaged=0;
+ staged=0;
+ ahead=0;
+ behind=0;
+ }
+ {
+ if (!after_first && $0 ~ /^##.+/) {
+ if ( match($0, /ahead ([1-9]+)/, a) ) {
+ ahead=a[1];
+ }
+ if ( match($0, /behind ([1-9]+)/, a) ) {
+ behind=a[1];
+ }
+ } else if ($0 ~ /^\?\? .+/) {
+ untracked += 1
+ } else {
+ if ($0 ~ /^.[^ ] .+/) {
+ unstaged += 1
+ }
+ if ($0 ~ /^[^ ]. .+/) {
+ staged += 1
+ }
+ }
+ after_first = 1
+ }
+ END {
+ if (!seen_header) {
+
+ }
+ print ahead ";" behind ";" untracked ";" unstaged ";" staged
+ }'
+end
+
+
+function prompt_git -d "Display the current git state"
+ set -l ref
+ if [ -e .git ]
+ set ref (command git symbolic-ref HEAD 2> /dev/null)
+ if [ $status -gt 0 ]
+ set -l branch (command git show-ref --head -s --abbrev |head -n1 2> /dev/null)
+ set ref "➦ $branch "
+ end
+ set branch_symbol \uE0A0
+ set -l branch (echo $ref | sed "s-refs/heads/-$branch_symbol -")
+
+ set -l BG PROMPT
+
+ set dirty ''
+ set gstatus ( git status --porcelain -b | git_status_summary )
+
+ # Check for commit ahead
+ set ahead (echo $gstatus | cut -d ';' -f 1)
+ # Check for commit behind
+ set behind (echo $gstatus | cut -d ';' -f 2)
+ # Check for modified files
+ set unstdg (echo $gstatus | cut -d ';' -f 3)
+ # Check for untracked files
+ set untrkd (echo $gstatus | cut -d ';' -f 4)
+ # Check for staged files
+ set staged (echo $gstatus | cut -d ';' -f 5)
+
+ if [ $ahead -gt 0 ]
+ set dirty $dirty'↑:'$ahead' '
+ end
+ if [ $behind -gt 0 ]
+ set dirty $dirty'↓:'$behind' '
+ end
+ if [ $untrkd -gt 0 ]
+ set dirty $dirty'U:'$untrkd' '
+ end
+ if [ $unstdg -gt 0 ]
+ set dirty $dirty'?:'$unstdg' '
+ end
+ if [ $staged -gt 0 ]
+ set dirty $dirty'S:'$staged' '
+ end
+
+
+ if [ $staged -eq 0 -a $untrkd -eq 0 ]
+ set BG green
+ set PROMPT "$branch $dirty"
+ else
+ set BG yellow
+
+ # Check if there's any commit in the repo
+ set -l empty 0
+ git rev-parse --quiet --verify HEAD > /dev/null ^&1; or set empty 1
+
+ set -l target
+ if [ $empty = 1 ]
+ # The repo is empty
+ set dirty ''
+ set target '4b825dc642cb6eb9a060e54bf8d69288fbee4904'
+
+ else
+ # The repo is not emtpy
+ set target 'HEAD'
+
+ # Check for unstaged change only when the repo is not empty
+ set -l unstaged 0
+ git diff --no-ext-diff --ignore-submodules=dirty --quiet --exit-code; or set unstaged 1
+ if [ $unstaged = 1 ]; set dirty $dirty'●'; end
+ end
+
+ # Check for staged change
+ set -l staged 0
+ git diff-index --cached --quiet --exit-code --ignore-submodules=dirty $target; or set staged 1
+ if [ $staged = 1 ]; set dirty $dirty'✚'; end
+
+ # Check for dirty
+ if [ "$dirty" = "" ]
+ set PROMPT "$branch"
+ else
+ set PROMPT "$branch $dirty"
+ end
+ end
+ prompt_segment $BG black $PROMPT
+ end
+end
+
+
+function prompt_status -d "the symbols for a non zero exit status, root and background jobs"
+ if [ $RETVAL -ne 0 ]
+ prompt_segment black red "✘"
+ end
+
+ # if superuser (uid == 0)
+ set -l uid (id -u $USER)
+ if [ $uid -eq 0 ]
+ prompt_segment black yellow "⚡"
+ end
+
+ # Jobs display
+ if [ (jobs -l | wc -l) -gt 0 ]
+ prompt_segment black cyan "⚙"
+ end
+end
+
+function available -a name -d "Check if a function or program is available."
+ type "$name" ^/dev/null >&2
+end
+
+function prompt_battery
+ set str (acpi | grep -oP 'Full|Charging|Discharging|\d+%|\d+:\d+' | tr --truncate-set1 '\n' ' ' | read charging percent time)
+
+ if [ $time = "" ]
+ set time "===="
+ end
+
+ if [ $charging = "Charging" ]
+ set charging "blue"
+ else if [ $charging = "Discharging" ]
+ set charging "green"
+ else
+ set charging "cyan"
+ end
+
+ set percent $percent
+
+ prompt_segment $charging white "$time $percent"
+end
+
+function prompt_time
+ prompt_segment white black (date "+%H:%M:%S")
+end
+
+#
+# Prompt
+#
+function fish_prompt
+ set -g RETVAL $status
+ prompt_time
+ prompt_status
+ prompt_virtual_env
+ prompt_user
+ prompt_dir
+ prompt_todo
+ prompt_shlv
+ available git; and prompt_git
+ prompt_finish
+end
diff --git a/functions/freboot.fish b/functions/freboot.fish
new file mode 100644
index 0000000..5e5b907
--- /dev/null
+++ b/functions/freboot.fish
@@ -0,0 +1 @@
+alias freboot='sudo kexec -l /boot/vmlinuz-linux --initrd=/boot/initramfs-linux.img --reuse-cmdline; sudo kexec -e'
diff --git a/functions/g++.fish b/functions/g++.fish
new file mode 100644
index 0000000..576389e
--- /dev/null
+++ b/functions/g++.fish
@@ -0,0 +1 @@
+ alias g++='g++ -std=c++11'
diff --git a/functions/gcc.fish b/functions/gcc.fish
new file mode 100644
index 0000000..deef5c9
--- /dev/null
+++ b/functions/gcc.fish
@@ -0,0 +1 @@
+alias gcc='gcc -std=c11'
diff --git a/functions/gccW.fish b/functions/gccW.fish
new file mode 100644
index 0000000..d79d4d4
--- /dev/null
+++ b/functions/gccW.fish
@@ -0,0 +1 @@
+alias gccW='gcc -W -Wall -pedantic -Werror'
diff --git a/functions/grep.fish b/functions/grep.fish
new file mode 100644
index 0000000..8c9a7a1
--- /dev/null
+++ b/functions/grep.fish
@@ -0,0 +1 @@
+alias grep='grep --color=auto'
diff --git a/functions/grepb.fish b/functions/grepb.fish
new file mode 100644
index 0000000..7c257f3
--- /dev/null
+++ b/functions/grepb.fish
@@ -0,0 +1 @@
+alias grepb="tr '[\000-\011\013-\037\177-\377]' '.' | grep"
diff --git a/functions/indent.fish b/functions/indent.fish
new file mode 100644
index 0000000..cad4cca
--- /dev/null
+++ b/functions/indent.fish
@@ -0,0 +1 @@
+alias indent='indent -i2 -kr --line-length500 -nbap'
diff --git a/functions/inhib.fish b/functions/inhib.fish
new file mode 100644
index 0000000..9b15b6a
--- /dev/null
+++ b/functions/inhib.fish
@@ -0,0 +1 @@
+alias inhib='systemd-inhibit --what=handle-lid-switch sleep 5d'
diff --git a/functions/ip.fish b/functions/ip.fish
new file mode 100644
index 0000000..f3b7d3a
--- /dev/null
+++ b/functions/ip.fish
@@ -0,0 +1 @@
+alias ip='ip -c' # Color with ip command
diff --git a/functions/l.fish b/functions/l.fish
new file mode 100644
index 0000000..8e25bd8
--- /dev/null
+++ b/functions/l.fish
@@ -0,0 +1 @@
+alias l='ls -CF'
diff --git a/functions/ll.fish b/functions/ll.fish
new file mode 100644
index 0000000..7e65e00
--- /dev/null
+++ b/functions/ll.fish
@@ -0,0 +1,3 @@
+function ll -d "ls long mode"
+ ls -alF
+end
diff --git a/functions/ls.fish b/functions/ls.fish
new file mode 100644
index 0000000..ca2ed68
--- /dev/null
+++ b/functions/ls.fish
@@ -0,0 +1 @@
+alias ls='ls --color=auto -F'
diff --git a/functions/man.fish b/functions/man.fish
new file mode 100644
index 0000000..33eab3e
--- /dev/null
+++ b/functions/man.fish
@@ -0,0 +1,10 @@
+function man --description "wrap the 'man' manual page opener to use color in formatting"
+ set -x LESS_TERMCAP_mb (printf "\033[01;31m")
+ set -x LESS_TERMCAP_md (printf "\033[01;31m")
+ set -x LESS_TERMCAP_me (printf "\033[0m")
+ set -x LESS_TERMCAP_se (printf "\033[0m")
+ set -x LESS_TERMCAP_so (printf "\033[01;44;33m")
+ set -x LESS_TERMCAP_ue (printf "\033[0m")
+ set -x LESS_TERMCAP_us (printf "\033[01;32m")
+ env man $argv
+end
diff --git a/functions/mkpause.fish b/functions/mkpause.fish
new file mode 100644
index 0000000..854c98d
--- /dev/null
+++ b/functions/mkpause.fish
@@ -0,0 +1 @@
+alias mkpause='sudo systemctl suspend'
diff --git a/functions/msf.fish b/functions/msf.fish
new file mode 100644
index 0000000..fc9d99e
--- /dev/null
+++ b/functions/msf.fish
@@ -0,0 +1 @@
+alias msf="msfconsole --quiet -x \"db_connect $USER@msf\""
diff --git a/functions/mv.fish b/functions/mv.fish
new file mode 100644
index 0000000..aa8879d
--- /dev/null
+++ b/functions/mv.fish
@@ -0,0 +1 @@
+alias mv='mv -i'
diff --git a/functions/off.fish b/functions/off.fish
new file mode 100644
index 0000000..6176247
--- /dev/null
+++ b/functions/off.fish
@@ -0,0 +1 @@
+alias off='déco;sudo poweroff'
diff --git a/functions/pacman.fish b/functions/pacman.fish
new file mode 100644
index 0000000..ab8c254
--- /dev/null
+++ b/functions/pacman.fish
@@ -0,0 +1 @@
+alias pacman 'sudo pacman'
diff --git a/functions/pass.fish b/functions/pass.fish
new file mode 100644
index 0000000..82dacfa
--- /dev/null
+++ b/functions/pass.fish
@@ -0,0 +1 @@
+alias pass='pass -c'
diff --git a/functions/reboot.fish b/functions/reboot.fish
new file mode 100644
index 0000000..f03b441
--- /dev/null
+++ b/functions/reboot.fish
@@ -0,0 +1 @@
+alias reboot='déco;sudo reboot'
diff --git a/functions/rv.fish b/functions/rv.fish
new file mode 100644
index 0000000..dc3662b
--- /dev/null
+++ b/functions/rv.fish
@@ -0,0 +1 @@
+alias rv='ssh achessh@ache.one -p 21 -R 60065:localhost:22 -fN'
diff --git a/functions/scanner.fish b/functions/scanner.fish
new file mode 100644
index 0000000..751ae22
--- /dev/null
+++ b/functions/scanner.fish
@@ -0,0 +1 @@
+alias scanner='sudo iwlist wlp3s0 scan | grep "\(Quality\|Address\|ESSID\)"'
diff --git a/functions/sec.fish b/functions/sec.fish
new file mode 100644
index 0000000..3dda398
--- /dev/null
+++ b/functions/sec.fish
@@ -0,0 +1,2 @@
+alias sec='ssh achessh@ache.one -p 21 -D 8886 -fN'
+
diff --git a/functions/t.fish b/functions/t.fish
new file mode 100644
index 0000000..50ee8db
--- /dev/null
+++ b/functions/t.fish
@@ -0,0 +1 @@
+alias t='todo' # Todo alias
diff --git a/functions/td.fish b/functions/td.fish
new file mode 100644
index 0000000..be7a59a
--- /dev/null
+++ b/functions/td.fish
@@ -0,0 +1 @@
+alias td='todo' # Todo alias
diff --git a/functions/wgetqp.fish b/functions/wgetqp.fish
new file mode 100644
index 0000000..a5b3527
--- /dev/null
+++ b/functions/wgetqp.fish
@@ -0,0 +1 @@
+alias wgetqp='wget -q --show-progress'
diff --git a/functions/ydx.fish b/functions/ydx.fish
new file mode 100644
index 0000000..070c6d9
--- /dev/null
+++ b/functions/ydx.fish
@@ -0,0 +1 @@
+alias ydx='youtube-dl -xi --audio-format mp3 ' # Youtube-dl alias