mirror of
https://github.com/arcan1s/dotfiles.git
synced 2025-04-24 16:07:17 +00:00
try to add some functions from oh-my-zsh
This commit is contained in:
parent
afa04de828
commit
330a1440af
@ -1,3 +1,12 @@
|
|||||||
|
# auto suggestion
|
||||||
|
if [[ -a "/usr/share/zsh/plugins/zsh-autosuggestions/zsh-autosuggestions.zsh" ]]; then
|
||||||
|
source "/usr/share/zsh/plugins/zsh-autosuggestions/zsh-autosuggestions.zsh"
|
||||||
|
else
|
||||||
|
source "$HOME/.zsh/zsh-autosuggestions/zsh-autosuggestions.zsh"
|
||||||
|
fi
|
||||||
|
ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE='fg=black'
|
||||||
|
|
||||||
|
|
||||||
# highlighting
|
# highlighting
|
||||||
if [[ -a "/usr/share/zsh/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh" ]]; then
|
if [[ -a "/usr/share/zsh/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh" ]]; then
|
||||||
source "/usr/share/zsh/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh"
|
source "/usr/share/zsh/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh"
|
||||||
|
61
zsh/sprunge
Normal file
61
zsh/sprunge
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
# Contributed and SLIGHTLY modded by Matt Parnell/ilikenwf <parwok -at- gmail>
|
||||||
|
# Created by the blogger at the URL below...I don't know where to find his/her name
|
||||||
|
# Original found at http://www.shellperson.net/sprunge-pastebin-script/
|
||||||
|
|
||||||
|
usage() {
|
||||||
|
description | fmt -s >&2
|
||||||
|
}
|
||||||
|
|
||||||
|
description() {
|
||||||
|
cat << HERE
|
||||||
|
|
||||||
|
DESCRIPTION
|
||||||
|
Upload data and fetch URL from the pastebin http://sprunge.us
|
||||||
|
|
||||||
|
USAGE
|
||||||
|
$0 filename.txt
|
||||||
|
$0 text string
|
||||||
|
$0 < filename.txt
|
||||||
|
piped_data | $0
|
||||||
|
|
||||||
|
NOTES
|
||||||
|
--------------------------------------------------------------------------
|
||||||
|
* INPUT METHODS *
|
||||||
|
$0 can accept piped data, STDIN redirection [<filename.txt], text strings following the command as arguments, or filenames as arguments. Only one of these methods can be used at a time, so please see the note on precedence. Also, note that using a pipe or STDIN redirection will treat tabs as spaces, or disregard them entirely (if they appear at the beginning of a line). So I suggest using a filename as an argument if tabs are important either to the function or readability of the code.
|
||||||
|
|
||||||
|
* PRECEDENCE *
|
||||||
|
STDIN redirection has precedence, then piped input, then a filename as an argument, and finally text strings as an arguments.
|
||||||
|
|
||||||
|
EXAMPLE:
|
||||||
|
echo piped | "$0" arguments.txt < stdin_redirection.txt
|
||||||
|
|
||||||
|
In this example, the contents of file_as_stdin_redirection.txt would be uploaded. Both the piped_text and the file_as_argument.txt are ignored. If there is piped input and arguments, the arguments will be ignored, and the piped input uploaded.
|
||||||
|
|
||||||
|
* FILENAMES *
|
||||||
|
If a filename is misspelled or doesn't have the necessary path description, it will NOT generate an error, but will instead treat it as a text string and upload it.
|
||||||
|
--------------------------------------------------------------------------
|
||||||
|
|
||||||
|
HERE
|
||||||
|
exit
|
||||||
|
}
|
||||||
|
sprunge() {
|
||||||
|
if [ -t 0 ]; then
|
||||||
|
echo Running interactively, checking for arguments... >&2
|
||||||
|
if [ "$*" ]; then
|
||||||
|
echo Arguments present... >&2
|
||||||
|
if [ -f "$*" ]; then
|
||||||
|
echo Uploading the contents of "$*"... >&2
|
||||||
|
cat "$*"
|
||||||
|
else
|
||||||
|
echo Uploading the text: \""$*"\"... >&2
|
||||||
|
echo "$*"
|
||||||
|
fi | curl -F 'sprunge=<-' http://sprunge.us
|
||||||
|
else
|
||||||
|
echo No arguments found, printing USAGE and exiting. >&2
|
||||||
|
usage
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo Using input from a pipe or STDIN redirection... >&2
|
||||||
|
curl -F 'sprunge=<-' http://sprunge.us
|
||||||
|
fi
|
||||||
|
}
|
77
zsh/urltools
Normal file
77
zsh/urltools
Normal file
@ -0,0 +1,77 @@
|
|||||||
|
# URL Tools
|
||||||
|
# Adds handy command line aliases useful for dealing with URLs
|
||||||
|
#
|
||||||
|
# Taken from:
|
||||||
|
# http://ruslanspivak.com/2010/06/02/urlencode-and-urldecode-from-a-command-line/
|
||||||
|
|
||||||
|
if [[ $(whence $URLTOOLS_METHOD) = "" ]]; then
|
||||||
|
URLTOOLS_METHOD=""
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ $(whence node) != "" && ( "x$URLTOOLS_METHOD" = "x" || "x$URLTOOLS_METHOD" = "xnode" ) ]]; then
|
||||||
|
alias urlencode='node -e "console.log(encodeURIComponent(process.argv[1]))"'
|
||||||
|
alias urldecode='node -e "console.log(decodeURIComponent(process.argv[1]))"'
|
||||||
|
elif [[ $(whence python) != "" && ( "x$URLTOOLS_METHOD" = "x" || "x$URLTOOLS_METHOD" = "xpython" ) ]]; then
|
||||||
|
alias urlencode='python -c "import sys, urllib as ul; print ul.quote_plus(sys.argv[1])"'
|
||||||
|
alias urldecode='python -c "import sys, urllib as ul; print ul.unquote_plus(sys.argv[1])"'
|
||||||
|
elif [[ $(whence xxd) != "" && ( "x$URLTOOLS_METHOD" = "x" || "x$URLTOOLS_METHOD" = "xshell" ) ]]; then
|
||||||
|
function urlencode() {echo $@ | tr -d "\n" | xxd -plain | sed "s/\(..\)/%\1/g"}
|
||||||
|
function urldecode() {printf $(echo -n $@ | sed 's/\\/\\\\/g;s/\(%\)\([0-9a-fA-F][0-9a-fA-F]\)/\\x\2/g')"\n"}
|
||||||
|
elif [[ $(whence ruby) != "" && ( "x$URLTOOLS_METHOD" = "x" || "x$URLTOOLS_METHOD" = "xruby" ) ]]; then
|
||||||
|
alias urlencode='ruby -r cgi -e "puts CGI.escape(ARGV[0])"'
|
||||||
|
alias urldecode='ruby -r cgi -e "puts CGI.unescape(ARGV[0])"'
|
||||||
|
elif [[ $(whence php) != "" && ( "x$URLTOOLS_METHOD" = "x" || "x$URLTOOLS_METHOD" = "xphp" ) ]]; then
|
||||||
|
alias urlencode='php -r "echo rawurlencode(\$argv[1]); echo \"\n\";"'
|
||||||
|
alias urldecode='php -r "echo rawurldecode(\$argv[1]); echo \"\\n\";"'
|
||||||
|
elif [[ $(whence perl) != "" && ( "x$URLTOOLS_METHOD" = "x" || "x$URLTOOLS_METHOD" = "xperl" ) ]]; then
|
||||||
|
if perl -MURI::Encode -e 1&> /dev/null; then
|
||||||
|
alias urlencode='perl -MURI::Encode -ep "uri_encode($ARGV[0]);"'
|
||||||
|
alias urldecode='perl -MURI::Encode -ep "uri_decode($ARGV[0]);"'
|
||||||
|
elif perl -MURI::Escape -e 1 &> /dev/null; then
|
||||||
|
alias urlencode='perl -MURI::Escape -ep "uri_escape($ARGV[0]);"'
|
||||||
|
alias urldecode='perl -MURI::Escape -ep "uri_unescape($ARGV[0]);"'
|
||||||
|
else
|
||||||
|
alias urlencode="perl -e '\$new=\$ARGV[0]; \$new =~ s/([^A-Za-z0-9])/sprintf(\"%%%02X\", ord(\$1))/seg; print \"\$new\n\";'"
|
||||||
|
alias urldecode="perl -e '\$new=\$ARGV[0]; \$new =~ s/\%([A-Fa-f0-9]{2})/pack(\"C\", hex(\$1))/seg; print \"\$new\n\";'"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
unset URLTOOLS_METHOD# URL Tools
|
||||||
|
# Adds handy command line aliases useful for dealing with URLs
|
||||||
|
#
|
||||||
|
# Taken from:
|
||||||
|
# http://ruslanspivak.com/2010/06/02/urlencode-and-urldecode-from-a-command-line/
|
||||||
|
|
||||||
|
if [[ $(whence $URLTOOLS_METHOD) = "" ]]; then
|
||||||
|
URLTOOLS_METHOD=""
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ $(whence node) != "" && ( "x$URLTOOLS_METHOD" = "x" || "x$URLTOOLS_METHOD" = "xnode" ) ]]; then
|
||||||
|
alias urlencode='node -e "console.log(encodeURIComponent(process.argv[1]))"'
|
||||||
|
alias urldecode='node -e "console.log(decodeURIComponent(process.argv[1]))"'
|
||||||
|
elif [[ $(whence python) != "" && ( "x$URLTOOLS_METHOD" = "x" || "x$URLTOOLS_METHOD" = "xpython" ) ]]; then
|
||||||
|
alias urlencode='python -c "import sys, urllib as ul; print ul.quote_plus(sys.argv[1])"'
|
||||||
|
alias urldecode='python -c "import sys, urllib as ul; print ul.unquote_plus(sys.argv[1])"'
|
||||||
|
elif [[ $(whence xxd) != "" && ( "x$URLTOOLS_METHOD" = "x" || "x$URLTOOLS_METHOD" = "xshell" ) ]]; then
|
||||||
|
function urlencode() {echo $@ | tr -d "\n" | xxd -plain | sed "s/\(..\)/%\1/g"}
|
||||||
|
function urldecode() {printf $(echo -n $@ | sed 's/\\/\\\\/g;s/\(%\)\([0-9a-fA-F][0-9a-fA-F]\)/\\x\2/g')"\n"}
|
||||||
|
elif [[ $(whence ruby) != "" && ( "x$URLTOOLS_METHOD" = "x" || "x$URLTOOLS_METHOD" = "xruby" ) ]]; then
|
||||||
|
alias urlencode='ruby -r cgi -e "puts CGI.escape(ARGV[0])"'
|
||||||
|
alias urldecode='ruby -r cgi -e "puts CGI.unescape(ARGV[0])"'
|
||||||
|
elif [[ $(whence php) != "" && ( "x$URLTOOLS_METHOD" = "x" || "x$URLTOOLS_METHOD" = "xphp" ) ]]; then
|
||||||
|
alias urlencode='php -r "echo rawurlencode(\$argv[1]); echo \"\n\";"'
|
||||||
|
alias urldecode='php -r "echo rawurldecode(\$argv[1]); echo \"\\n\";"'
|
||||||
|
elif [[ $(whence perl) != "" && ( "x$URLTOOLS_METHOD" = "x" || "x$URLTOOLS_METHOD" = "xperl" ) ]]; then
|
||||||
|
if perl -MURI::Encode -e 1&> /dev/null; then
|
||||||
|
alias urlencode='perl -MURI::Encode -ep "uri_encode($ARGV[0]);"'
|
||||||
|
alias urldecode='perl -MURI::Encode -ep "uri_decode($ARGV[0]);"'
|
||||||
|
elif perl -MURI::Escape -e 1 &> /dev/null; then
|
||||||
|
alias urlencode='perl -MURI::Escape -ep "uri_escape($ARGV[0]);"'
|
||||||
|
alias urldecode='perl -MURI::Escape -ep "uri_unescape($ARGV[0]);"'
|
||||||
|
else
|
||||||
|
alias urlencode="perl -e '\$new=\$ARGV[0]; \$new =~ s/([^A-Za-z0-9])/sprintf(\"%%%02X\", ord(\$1))/seg; print \"\$new\n\";'"
|
||||||
|
alias urldecode="perl -e '\$new=\$ARGV[0]; \$new =~ s/\%([A-Fa-f0-9]{2})/pack(\"C\", hex(\$1))/seg; print \"\$new\n\";'"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
unset URLTOOLS_METHOD
|
55
zsh/websearch
Normal file
55
zsh/websearch
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
# web_search from terminal
|
||||||
|
|
||||||
|
function web_search() {
|
||||||
|
emulate -L zsh
|
||||||
|
|
||||||
|
# define search engine URLS
|
||||||
|
typeset -A urls
|
||||||
|
urls=(
|
||||||
|
google "https://www.google.com/search?q="
|
||||||
|
bing "https://www.bing.com/search?q="
|
||||||
|
yahoo "https://search.yahoo.com/search?p="
|
||||||
|
duckduckgo "https://www.duckduckgo.com/?q="
|
||||||
|
yandex "https://yandex.ru/yandsearch?text="
|
||||||
|
github "https://github.com/search?q="
|
||||||
|
baidu "https://www.baidu.com/s?wd="
|
||||||
|
ecosia "https://www.ecosia.org/search?q="
|
||||||
|
)
|
||||||
|
|
||||||
|
# check whether the search engine is supported
|
||||||
|
if [[ -z "$urls[$1]" ]]; then
|
||||||
|
echo "Search engine $1 not supported."
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# search or go to main page depending on number of arguments passed
|
||||||
|
if [[ $# -gt 1 ]]; then
|
||||||
|
# build search url:
|
||||||
|
# join arguments passed with '+', then append to search engine URL
|
||||||
|
url="${urls[$1]}${(j:+:)@[2,-1]}"
|
||||||
|
else
|
||||||
|
# build main page url:
|
||||||
|
# split by '/', then rejoin protocol (1) and domain (2) parts with '//'
|
||||||
|
url="${(j://:)${(s:/:)urls[$1]}[1,2]}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
open_command "$url"
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
alias bing='web_search bing'
|
||||||
|
alias google='web_search google'
|
||||||
|
alias yahoo='web_search yahoo'
|
||||||
|
alias ddg='web_search duckduckgo'
|
||||||
|
alias yandex='web_search yandex'
|
||||||
|
alias github='web_search github'
|
||||||
|
alias baidu='web_search baidu'
|
||||||
|
alias ecosia='web_search ecosia'
|
||||||
|
|
||||||
|
#add your own !bang searches here
|
||||||
|
alias wiki='web_search duckduckgo \!w'
|
||||||
|
alias news='web_search duckduckgo \!n'
|
||||||
|
alias youtube='web_search duckduckgo \!yt'
|
||||||
|
alias map='web_search duckduckgo \!m'
|
||||||
|
alias image='web_search duckduckgo \!i'
|
||||||
|
alias ducky='web_search duckduckgo \!'
|
1
zsh/zsh-autosuggestions
Submodule
1
zsh/zsh-autosuggestions
Submodule
@ -0,0 +1 @@
|
|||||||
|
Subproject commit ba029e83d0aa2d859d7ac46299462fa5b5a43a68
|
Loading…
Reference in New Issue
Block a user