Skip to content

Instantly share code, notes, and snippets.

@Wintus
Last active February 1, 2019 03:34
Show Gist options
  • Save Wintus/7a2bb056753c8fc12f3fa583969cd162 to your computer and use it in GitHub Desktop.
Save Wintus/7a2bb056753c8fc12f3fa583969cd162 to your computer and use it in GitHub Desktop.
Fish functions
# Defined in - @ line 0
function arg --description 'alias arg xargs -n 1'
xargs -n 1 $argv;
end
function cdf --description 'cd to dir on Finder window'
set -l target (osascript -e 'tell application "Finder" to if (count of Finder windows) > 0 then get POSIX path of (target of front Finder window as text)')
if test -n $target
cd "$target"
pwd
else
echo "No finder window found" ^&2
end
end
function cmdranking --description 'Show command history ordered by frequency'
history | awk '{print $1}' | sort | uniq -c | sort -nr
end
function compws --description 'Trim out spaces and squeeze spaces in-between'
echo $argv | awk '{$1=$1;print}'
end
function fish_prompt
echo ""
echo -n "["
set_color blue
echo -n (date "+%m/%d-%T")
set_color normal
echo -n "] "
set_color cyan
echo -n (whoami)
set_color normal
echo -n ": "
set_color brown
echo (prompt_pwd)
set_color green
echo -n " ><(((*> "
set_color normal
end
function dicuse --description 'Look up usages of a word from EJJE dic'
set --local head "用例"
w3m -dump -cols 200 "http://ejje.weblio.jp/content/$argv" \
| grep "$head" \
| sed -E -e 's/\[.+MorePl\]//' -e "s/^.*$head +//" \
| grep -E --color=always "\b$argv" \
| nl
end
alias dic 'dicuse'
# Defined in /var/folders/_w/m31lypps4bv10q598fdcgcnm0000gn/T//fish.lBf6wB/double-quote.fish @ line 2
function double-quote
echo '"'$argv'"'
end
# Defined in - @ line 0
function e --description 'alias e emacsclient --alternate-editor /usr/local/bin/vim -c'
emacsclient --alternate-editor /usr/local/bin/vim -c $argv &
end
# Defined in /var/folders/_w/m31lypps4bv10q598fdcgcnm0000gn/T//fish.MEtOhZ/each.fish @ line 2
function each
fmt -1 $argv
end
function err --description 'Print string into STDERR'
echo "["(date +%FT%T%z)"]: $argv" ^&2
end
function f
open .
end
# Defined in - @ line 0
function g --description 'alias g cd (ghq root)/(ghq list | peco)'
cd (ghq root)/(ghq list | peco) $argv;
end
# Wrap git automatically by adding the following to ~/.config/fish/functions/git.fish:
function git --description 'Alias for hub, which wraps git to provide extra functionality with GitHub.'
hub $argv
end
function h
cd ~ $argv;
end
function highlight --description 'highlight <pattern> <file>'
# set p $argv[1]
# set --erase $argv[1]
grep --color -E "\$|$argv[1]" $argv[2..-1]
end
function isodate
date -I $argv;
end
function l
ls $argv;
end
# Defined in - @ line 0
function lesf --description 'alias lesf less +F -R'
less +F -R $argv;
end
# Defined in /var/folders/_w/m31lypps4bv10q598fdcgcnm0000gn/T//fish.GwYDvG/ll.fish @ line 2
function ll --description 'alias ll exa -lh --git --time-style iso'
exa -Falh --git --time-style iso $argv;
end
function maze
command maze --format color --interactive $argv;
end
function peco-lscd --description 'peco the current directory and cd to the selection'
set -l dir (find (pwd) -maxdepth 1 -type d | sed -e 's|\./||' | peco)
if test -n dir
cd "$dir"
end
end
function ppjson
python -c 'import sys,json;print json.dumps(json.loads(sys.stdin.read()),indent=4,ensure_ascii=False)' $argv;
end
function rand
od -A n -t u4 -N 4 /dev/urandom | tr -d "[:blank:]" $argv;
end
function relogin
exec fish -l
end
function repeat --description 'repeat command. arg: number command'
set -l n $argv[1]
for i in (seq $n)
eval $argv[2..-1]
end
end
function sha1 --description 'Encode by sha1'
echo $argv | shasum | perl -pe "s|^\s*(\w+)\s+.*\$|\$1|"
end
function tmp --description 'alias tmp cd (mktemp -d)'
cd (mktemp -d) $argv;
end
function tmpfile --description 'create temp file with extension'
set -lx ext $argv[1]
set -lx filename (mktemp -q)
mv $filename{,.$ext}
echo $filename.$ext
end
function up --description "go up n directories"
cd (ruby -e 'n = ($*.first || 1).to_i; path = %(../) * n; puts path' $argv);
end
# Defined in - @ line 0
function urldecode --description 'alias urldecode nkf -w --url-input'
nkf -w --url-input $argv;
end
# Defined in /var/folders/_w/m31lypps4bv10q598fdcgcnm0000gn/T//fish.uba9Pm/urlencode.fish @ line 2
function urlencode --description url-encode
echo $argv | nkf -WwMQ | tr '=' '%'
end
function vulnerablility
env x="() { :;}; echo this bash is vulnerable" bash -c : $argv;
end
@Wintus
Copy link
Author

Wintus commented Aug 13, 2018

dicuse may be rewritable by scrapy?

https://scrapy.org/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment