From ed37914a24521abc5e0abbfa315552b427b93830 Mon Sep 17 00:00:00 2001 From: Mathieu Maret Date: Mon, 6 Sep 2021 22:10:22 +0200 Subject: [PATCH] zsh: add various alias --- .zsh/30_alias.zsh | 2 ++ .zsh/40_function.zsh | 36 ++++++++++++++++++++++++++++++++---- 2 files changed, 34 insertions(+), 4 deletions(-) diff --git a/.zsh/30_alias.zsh b/.zsh/30_alias.zsh index 19dc3a9..c66b6d3 100644 --- a/.zsh/30_alias.zsh +++ b/.zsh/30_alias.zsh @@ -4,6 +4,7 @@ alias mkdir='nocorrect mkdir' alias rm='nocorrect rm' alias sudo='nocorrect sudo' alias tm='tmux attach || tmux' +alias zzz='systemctl hibernate' #alias @@ -12,6 +13,7 @@ alias l='ls' alias ll='ls --color=auto -lh' alias la='ls --color=auto -lha' alias lll='ls --color -lh | less -R' +alias lsd="ls -d */" alias lsg='ls | grep -i ' alias ..='cd ..' alias ../..='cd ../..' diff --git a/.zsh/40_function.zsh b/.zsh/40_function.zsh index 49d30c8..b74e3ea 100755 --- a/.zsh/40_function.zsh +++ b/.zsh/40_function.zsh @@ -135,10 +135,12 @@ resgrep () { done } -sgrep() { - find -E . -name .repo -prune -o -name .git -prune -o -type f -iregex '.*\.(c|h|cc|cpp|S|java|xml|sh|mk|aidl)' -print0 | xargs -0 grep --color -n "$@" +sgrep(){ + find . -name .repo -prune -o -name .git -prune -o -type f -iregex '.*\.\(c\|h\|cc\|cpp\|hpp\|S\|java\|xml\|sh\|mk\|aidl\|vts\)' \ + -exec grep --color -n "$@" {} + } + mangrep() { find . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -type f -name 'AndroidManifest.xml' -print0 | xargs -0 grep --color -n "$@" } @@ -152,6 +154,30 @@ docgrep () { find . -name .repo -prune -o -name .git -prune -o -type f \( -name '*.doc' -o -name '*.docx' -o -name '*.pdf' -o -name '*.odt' \) -print0 | xargs -i -0 docgrepfile {} "$@" } +ggrep() +{ + find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.gradle" \ + -exec grep --color -n "$@" {} + +} + +gogrep() +{ + find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.go" \ + -exec grep --color -n "$@" {} + +} + +mgrep() +{ + find . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o \( -regextype posix-egrep -iregex '(.*\/Makefile|.*\/Makefile\..*|.*\.make|.*\.mak|.*\.mk|.*\.bp)' -o -regextype posix-extended -regex '(.*/)?(build|soong)/.*[^/]*\.go' \) -type f \ + -exec grep --color -n "$@" {} + +} + +treegrep() +{ + find . -name .repo -prune -o -name .git -prune -o -regextype posix-egrep -iregex '.*\.(c|h|cpp|hpp|S|java|xml)' -type f \ + -exec grep --color -n -i "$@" {} + +} + findduplicate () { find . -name .repo -prune -o -name .git -prune -o -not -empty -type f -printf "%s\n" | sort -rn | uniq -d | xargs -I{} -n1 find -type f -size {}c -print0 | xargs -0 md5sum | sort | uniq -w32 --all-repeated=separate @@ -226,7 +252,7 @@ sudocker(){ sdocker (){ DOCKER_SSH_AUTH=$HOME/docker_ssh_auth - AOSP_IMAGE=${AOSP_IMAGE:-$HOME/Project} + AOSP_IMAGE=${AOSP_IMAGE:-$HOME/Sources/android} if [ $# -eq 0 ]; then echo "Usage: $0 DOCKER_IMAGE_NAME" @@ -248,7 +274,7 @@ sdocker (){ img=$(docker ps -a | grep $1 | awk '{print $1}' | head -1); if [ -z $img ]; then echo "Running a new container" - docker run ${AOSP_ARGS} ${=SSH_AUTH_ARGS} -v ${AOSP_IMAGE}:/aosp/Project -v /media/mmaret/data_wd:/aosp/data_wd -v /media/mmaret/data:/aosp/data --user="$(id -u):$(id -g)" $1 + docker run ${AOSP_ARGS} ${=SSH_AUTH_ARGS} -v ${AOSP_IMAGE}:/aosp/Project -v /home/mathieu/pixium/:/aosp/pixium/ -v /local/:/local/ -v /media/mmaret/data:/aosp/data -v /home/mathieu/miyoo/:/aosp/miyoo --user="$(id -u):$(id -g)" $1 else echo "Starting $img" docker start -i -a $img @@ -286,3 +312,5 @@ imv() { [[ $src != $dst ]] && mkdir -p $dst:h && mv -n $src $dst done } + +transfer(){ if [ $# -eq 0 ];then echo "No arguments specified.\nUsage:\n transfer \n ... | transfer ">&2;return 1;fi;if tty -s;then file="$1";file_name=$(basename "$file");if [ ! -e "$file" ];then echo "$file: No such file or directory">&2;return 1;fi;if [ -d "$file" ];then file_name="$file_name.zip" ,;(cd "$file"&&zip -r -q - .)|curl --progress-bar --upload-file "-" "http://transfer.sh/$file_name"|tee /dev/null,;else cat "$file"|curl --progress-bar --upload-file "-" "http://transfer.sh/$file_name"|tee /dev/null;fi;else file_name=$1;curl --progress-bar --upload-file "-" "http://transfer.sh/$file_name"|tee /dev/null;fi;}