Skip to content

Instantly share code, notes, and snippets.

@amorenew
Created June 4, 2024 18:22
Show Gist options
  • Save amorenew/7feef8b9fa26633707190270b29d331b to your computer and use it in GitHub Desktop.
Save amorenew/7feef8b9fa26633707190270b29d331b to your computer and use it in GitHub Desktop.
My default aliases for zsh or bash
export PATH="$PATH":"$HOME/.pub-cache/bin"
export EDITOR=nano
export VISUAL="$EDITOR"
export GPG_TTY=$(tty)
#export PATH="/Library/Frameworks/Python.framework/Versions/3.7/bin:${PATH}"
# vscode as editor
# git config --global core.editor "code --wait"
# undo it >> git config --global --unset core.editor
# Aliases
# open bash
alias edit="open ~/.aliases"
# open bash
alias editA="open ~/.bashrc ~/.zshrc "
# open bash
alias editT="open ~/.oh-my-zsh/themes/gnzh.zsh-theme"
# ment ssh
# add ssh switch permission
alias amrPerm='chmod +x /Users/amr/.ssh/ssh_switch_amr.sh'
alias mentPerm='chmod +x /Users/amr/.ssh/ssh_switch_ment.sh'
alias amr='~/.ssh/ssh_switch_amr.sh'
alias ment='~/.ssh/ssh_switch_ment.sh'
#alias sshMent="git config core.sshCommand "ssh -i ~/.ssh/ment_id_ed25519 -o IdentitiesOnly=yes""
#alias sshAmr="git config core.sshCommand "ssh -i ~/.ssh/amr_id_ed25519 -o IdentitiesOnly=yes""
#alias gitMent='GIT_SSH_COMMAND="ssh -i ~/.ssh/ment_id_ed25519" git'
#alias gitAmr='GIT_SSH_COMMAND="ssh -i ~/.ssh/amr_id_ed25519" git'
# convert images to webp
# in case parallel is not installed, use brew install parallel
alias jpgWebp='find . -name "*.jpg" | parallel -eta cwebp {} -o {.}.webp'
alias jpegWebp='find . -name "*.jpeg" | parallel -eta cwebp {} -o {.}.webp'
alias pngWebp='find . -name "*.png" | parallel -eta cwebp {} -o {.}.webp'
# run on all devices
alias all='flutter run -d all'
# ai for llama3
alias ai='ollama run llama3'
# screen
alias screen='scrcpy'
# build runner
alias b='dart run build_runner build --delete-conflicting-outputs'
# check dart dep check
alias dep="pub global run dep_check"
# check dart dep check
alias pub="flutter pub get"
# check dart dep check
alias outdated="flutter pub outdated"
# clear terminal
alias c="clear"
# build runner
alias bu="flutter pub run build_runner build --delete-conflicting-outputs"
# format dart code
alias fix="dart fix --apply ./"
# format dart code
alias f="dart format ./"
# push to main branch
alias main="dart format ./lib && git push origin dev"
# push to current branch
alias force="git push --force"
# push to current branch
alias push="git push origin HEAD"
# push to current branch
alias pull="git pull upstream HEAD"
# git soft reset
alias soft="git reset --soft HEAD^"
# amend to commit
alias amend="git commit --amend"
# rename a branch
alias rename="git branch -m $@"
# merge to dev branch
alias merge="git merge origin dev"
# merge to master branch
alias mergeMaster="git merge origin master"
branch_checkout () {
git checkout -b $1 origin/dev
}
# create branch
alias checkout=branch_checkout $@
branch_delete () {
git checkout -D $1
}
# delete branch
alias del=branch_delete $@
# commit
alias m='git commit -m "$@"'
# commit request changes
alias change='git commit -m "refactor: change requests"'
# stash by message
alias save='git stash push -m "$@"'
# pop last stash
alias pop='git stash pop'
# apply stash by name
alias apply='git stash apply stash^{/$@}'
# decorate log
alias dec="git log --oneline --graph -4 --decorate"
# reset to previous commit
alias reset="git reset --soft HEAD~1"
alias stashy=" git pull origin dev --rebase --autostash"
alias updateAll="find . -maxdepth 2 -type d -exec sh -c '(cd {} && git fetch && git pull --rebase --autostash)' ';'"
alias pubAll="find . -maxdepth 2 -type d -exec sh -c '(cd {} && flutter pub get)' ';'"
alias subAll="find . -maxdepth 2 -type d -exec sh -c '(cd {} && git submodule foreach --recursive git reset --hard && git submodule update --init --remote --recursive)' ';'"
alias sub="git submodule update --init --remote --recursive"
alias fullUpdate="updateAll && pubAll && subAll"
@amorenew
Copy link
Author

amorenew commented Jun 4, 2024

#.zshrc

# If you come from bash you might have to change your $PATH.
# export PATH=$HOME/bin:/usr/local/bin:$PATH

# Path to your oh-my-zsh installation.
export ZSH="$HOME/.oh-my-zsh"

if [ -s ~/.aliases ]; then
    source ~/.aliases;
fi

## [Completion]
## Completion scripts setup. Remove the following line to uninstall
[[ -f /Users/amr/.dart-cli-completion/zsh-config.zsh ]] && . /Users/amr/.dart-cli-completion/zsh-config.zsh || true
## [/Completion]

# C and C++ compiling
export CC=$(xcrun --find clang)
export CXX=$(xcrun --find clang++)

# Node.js or npm
export PATH=/usr/local/share/npm/bin:$PATH

# Python
export PATH="/usr/local/opt/python/libexec/bin:$PATH"

# Java
#export PATH="/usr/local/opt/openjdk/bin:$PATH"
export JAVA_HOME=$(/usr/libexec/java_home -v 11)
export PATH=$JAVA_HOME/bin:$PATH

# gem tools exporting for ruby
export GEM_HOME=$HOME/.gem
export PATH=$GEM_HOME/bin:$PATH
export PATH=$HOME/.gem/bin:$PATH
export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init -)"

#Android SDK exporting 
export ANDROID_HOME=$HOME/Desktop/private/programming/sdks
export PATH=$PATH:$HOME/Desktop/private/programming/sdks/Android/sdk/platform-tools
export PATH=$PATH:$HOME/Desktop/private/programming/sdks/Android/sdk/tools
export PATH=$PATH:$HOME/Desktop/private/programming/sdks/Android/sdk/ndk/27.0.11718014

#Flutter binary exporting
export PATH=$PATH:$HOME/fvm/versions/stable/bin

## open vscode by code .
[[ "$TERM_PROGRAM" == "vscode" ]] && . "$(code --locate-shell-integration-path zsh)"

# Set name of the theme to load --- if set to "random", it will
# load a random theme each time oh-my-zsh is loaded, in which case,
# to know which specific one was loaded, run: echo $RANDOM_THEME
# See https://github.com/ohmyzsh/ohmyzsh/wiki/Themes
ZSH_THEME="gnzh"
#gnzh
#cloud
#robbyrussell
# Set list of themes to pick from when loading at random
# Setting this variable when ZSH_THEME=random will cause zsh to load
# a theme from this variable instead of looking in $ZSH/themes/
# If set to an empty array, this variable will have no effect.
# ZSH_THEME_RANDOM_CANDIDATES=( "robbyrussell" "agnoster" )

# Uncomment the following line to use case-sensitive completion.
# CASE_SENSITIVE="true"

# Uncomment the following line to use hyphen-insensitive completion.
# Case-sensitive completion must be off. _ and - will be interchangeable.
# HYPHEN_INSENSITIVE="true"

# Uncomment one of the following lines to change the auto-update behavior
# zstyle ':omz:update' mode disabled  # disable automatic updates
# zstyle ':omz:update' mode auto      # update automatically without asking
# zstyle ':omz:update' mode reminder  # just remind me to update when it's time

# Uncomment the following line to change how often to auto-update (in days).
# zstyle ':omz:update' frequency 13

# Uncomment the following line if pasting URLs and other text is messed up.
# DISABLE_MAGIC_FUNCTIONS="true"

# Uncomment the following line to disable colors in ls.
# DISABLE_LS_COLORS="true"

# Uncomment the following line to disable auto-setting terminal title.
# DISABLE_AUTO_TITLE="true"

# Uncomment the following line to enable command auto-correction.
# ENABLE_CORRECTION="true"

# Uncomment the following line to display red dots whilst waiting for completion.
# You can also set it to another string to have that shown instead of the default red dots.
# e.g. COMPLETION_WAITING_DOTS="%F{yellow}waiting...%f"
# Caution: this setting can cause issues with multiline prompts in zsh < 5.7.1 (see #5765)
# COMPLETION_WAITING_DOTS="true"

# Uncomment the following line if you want to disable marking untracked files
# under VCS as dirty. This makes repository status check for large repositories
# much, much faster.
# DISABLE_UNTRACKED_FILES_DIRTY="true"

# Uncomment the following line if you want to change the command execution time
# stamp shown in the history command output.
# You can set one of the optional three formats:
# "mm/dd/yyyy"|"dd.mm.yyyy"|"yyyy-mm-dd"
# or set a custom format using the strftime function format specifications,
# see 'man strftime' for details.
# HIST_STAMPS="mm/dd/yyyy"

# Would you like to use another custom folder than $ZSH/custom?
# ZSH_CUSTOM=/path/to/new-custom-folder

# Which plugins would you like to load?
# Standard plugins can be found in $ZSH/plugins/
# Custom plugins may be added to $ZSH_CUSTOM/plugins/
# Example format: plugins=(rails git textmate ruby lighthouse)
# Add wisely, as too many plugins slow down shell startup.
plugins=(git)

source $ZSH/oh-my-zsh.sh

# User configuration

# export MANPATH="/usr/local/man:$MANPATH"

# You may need to manually set your language environment
# export LANG=en_US.UTF-8

# Preferred editor for local and remote sessions
# if [[ -n $SSH_CONNECTION ]]; then
#   export EDITOR='vim'
# else
#   export EDITOR='mvim'
# fi

# Compilation flags
# export ARCHFLAGS="-arch x86_64"

# Set personal aliases, overriding those provided by oh-my-zsh libs,
# plugins, and themes. Aliases can be placed here, though oh-my-zsh
# users are encouraged to define aliases within the ZSH_CUSTOM folder.
# For a full list of active aliases, run `alias`.
#
# Example aliases
# alias zshconfig="mate ~/.zshrc"
# alias ohmyzsh="mate ~/.oh-my-zsh"

@amorenew
Copy link
Author

amorenew commented Jun 4, 2024

/Users/amr/.oh-my-zsh/themes/gnzh.zsh-theme
My modified gnzh theme

# Based on bira theme

setopt prompt_subst

() {

local PR_USER PR_USER_OP PR_PROMPT PR_HOST

# Check the UID
if [[ $UID -ne 0 ]]; then # normal user
  PR_USER='%F{green}%n%f'
  PR_USER_OP='%F{green}%#%f'
  PR_PROMPT='%f➤ %f'
else # root
  PR_USER='%F{red}%n%f'
  PR_USER_OP='%F{red}%#%f'
  PR_PROMPT='%F{red}➤ %f'
fi

# Check if we are on SSH or not
if [[ -n "$SSH_CLIENT"  ||  -n "$SSH2_CLIENT" ]]; then
  PR_HOST='%F{red}%M%f' # SSH
else
  PR_HOST='%F{green}%m%f' # no SSH
fi


local return_code="%(?..%F{red}%? ↵%f)"

local user_host="${PR_USER}%F{cyan}@${PR_HOST}"
local current_dir="%B%F{blue}%2~"
local git_branch='$(git_prompt_info)'

PROMPT="╭─${current_dir}\$(ruby_prompt_info) ${git_branch}
╰─$PR_PROMPT "
RPROMPT="${return_code}"

ZSH_THEME_GIT_PROMPT_PREFIX="%F{yellow}‹"
ZSH_THEME_GIT_PROMPT_SUFFIX="› %f"
ZSH_THEME_RUBY_PROMPT_PREFIX="%F{red}‹"
ZSH_THEME_RUBY_PROMPT_SUFFIX="›%f"

}

@amorenew
Copy link
Author

amorenew commented Jun 6, 2024

for windows follow
go to regedit then HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Command Processor
Add String Value entry with the name AutoRun and the full path of your .bat/.cmd file.
image

For example, %USERPROFILE%\alias.cmd, replacing the initial segment of the path with %USERPROFILE% is useful for syncing among multiple machines.

@echo off
:: Setting environment variables
set PATH=%PATH%;%USERPROFILE%\.pub-cache\bin
set EDITOR=nano
set VISUAL=nano
:: Note: GPG_TTY is not applicable in Windows environment

:: Git editor setup
:: git config --global core.editor "code --wait"
:: To unset it:
:: git config --global --unset core.editor

:: DOSKEY macros
doskey edit=notepad %USERPROFILE%\alias.cmd
doskey editA=notepad %USERPROFILE%\.bashrc %USERPROFILE%\.zshrc
doskey editT=notepad %USERPROFILE%\.oh-my-zsh\themes\gnzh.zsh-theme

doskey amrPerm=icacls %USERPROFILE%\.ssh\ssh_switch_amr.sh /grant Everyone:(X)
doskey mentPerm=icacls %USERPROFILE%\.ssh\ssh_switch_ment.sh /grant Everyone:(X)
doskey amr="%USERPROFILE%\.ssh\ssh_switch_amr.sh"
doskey ment="%USERPROFILE%\.ssh\ssh_switch_ment.sh"

doskey all=flutter run -d all
doskey ai=ollama run llama3
doskey screen=scrcpy
doskey b=dart run build_runner build --delete-conflicting-outputs
doskey dep=pub global run dep_check
doskey pub=flutter pub get
doskey outdated=flutter pub outdated
doskey c=cls
doskey bu=flutter pub run build_runner build --delete-conflicting-outputs
doskey fix=dart fix --apply ./
doskey f=dart format ./
doskey main=dart format ./lib ^&^& git push origin dev
doskey force=git push --force
doskey push=git push origin HEAD
doskey pull=git pull upstream HEAD
doskey soft=git reset --soft HEAD^
doskey amend=git commit --amend
doskey rename=git branch -m $*
doskey merge=git merge origin dev
doskey mergeMaster=git merge origin master

doskey checkout=git checkout -b $1 origin/dev
doskey del=git branch -D $1

doskey m=git commit -m "$*"
doskey change=git commit -m "refactor: change requests"
doskey save=git stash push -m "$*"
doskey pop=git stash pop
doskey apply=git stash apply stash^{/$*}
doskey dec=git log --oneline --graph -4 --decorate
doskey reset=git reset --soft HEAD~1
doskey stashy=git pull origin dev --rebase --autostash

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