mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2024-10-16 11:40:46 +00:00
Compare commits
7 commits
0b5e62264e
...
239cfddf33
Author | SHA1 | Date | |
---|---|---|---|
|
239cfddf33 | ||
|
1514145a09 | ||
|
99e2c31484 | ||
|
e52598a5cc | ||
|
d91944d47e | ||
|
865291cb7a | ||
|
8b95897adb |
10 changed files with 158 additions and 28 deletions
12
lib/git.zsh
12
lib/git.zsh
|
@ -162,6 +162,18 @@ function git_current_branch() {
|
|||
echo ${ref#refs/heads/}
|
||||
}
|
||||
|
||||
# Outputs the name of the previously checked out branch
|
||||
# Usage example: git pull origin $(git_current_branch)
|
||||
# rev-parse --symbolic-full-name @{-1} only prints if it is a branch
|
||||
function git_previous_branch() {
|
||||
local ref
|
||||
ref=$(__git_prompt_git rev-parse --quiet --symbolic-full-name @{-1} 2> /dev/null)
|
||||
local ret=$?
|
||||
if [[ $ret != 0 ]] || [[ -z $ref ]]; then
|
||||
return # no git repo or non-branch previous ref
|
||||
fi
|
||||
echo ${ref#refs/heads/}
|
||||
}
|
||||
|
||||
# Gets the number of commits ahead from remote
|
||||
function git_commits_ahead() {
|
||||
|
|
52
plugins/backupzshrc/README.md
Normal file
52
plugins/backupzshrc/README.md
Normal file
|
@ -0,0 +1,52 @@
|
|||
# Oh My Zsh Backup Plugin
|
||||
|
||||
This plugin provides a convenient way to back up your `~/.zshrc` file locally and to a GitHub repository. It automatically detects changes in the `.zshrc` file, commits them with a timestamped message, and pushes changes to the specified GitHub repository. If you ever rm your zshrc, simply go to your Github repo and check it out.
|
||||
|
||||
## Dependencies
|
||||
1. Locally installed git with a git config for pulling the repo url and username
|
||||
2. A repo in Github https://github.com/yourusername/oh-my-zsh-backup
|
||||
Example: https://github.com/yourusername/oh-my-zsh-backup
|
||||
3. Push privileges configured to the main/master origin branch
|
||||
4. Create directory privileges for this script - create "$HOME/projects/backups" manually otherwise
|
||||
|
||||
## Installation
|
||||
|
||||
1. Clone this repository into your Oh My Zsh custom plugins directory:
|
||||
|
||||
```bash
|
||||
git clone https://github.com/yourusername/oh-my-zsh-backup ~/.oh-my-zsh/custom/plugins/backup
|
||||
```
|
||||
|
||||
2. Add `backup` to the plugins array in your `~/.zshrc` file:
|
||||
|
||||
```bash
|
||||
plugins=(... backup)
|
||||
```
|
||||
|
||||
3. Restart your terminal.
|
||||
|
||||
## Usage
|
||||
|
||||
Simply open your terminal or source your `~/.zshrc` file, and the backup will be triggered automatically. Any changes detected in `~/.zshrc` will be backed up to the specified GitHub repository.
|
||||
|
||||
## Configuration
|
||||
|
||||
### GitHub Username
|
||||
|
||||
If your GitHub username is not already set globally, the plugin will prompt you to enter it the first time you run it. Alternatively, you can set it manually using:
|
||||
|
||||
```bash
|
||||
git config --global user.name "Your Username"
|
||||
```
|
||||
|
||||
### Branch
|
||||
|
||||
By default, the plugin pushes changes to the branch specified GitHub repository is checked out to locally in the "$HOME/projects/backups" backup directory. You can change the target branch by checking out to a new branch in the backup directory.
|
||||
|
||||
## Contributions
|
||||
|
||||
Contributions are welcome! If you encounter any issues or have suggestions for improvements, please feel free to open an issue or submit a pull request on GitHub.
|
||||
|
||||
## License
|
||||
|
||||
This plugin is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.
|
54
plugins/backupzshrc/backupzshrc.plugin.zsh
Normal file
54
plugins/backupzshrc/backupzshrc.plugin.zsh
Normal file
|
@ -0,0 +1,54 @@
|
|||
function backup_zshrc() {
|
||||
# Function to back up ~/.zshrc locally and to a GitHub repository
|
||||
# Runs every time zsh is opened or source ~/.zshrc is run
|
||||
# Checks for git changes, will commit and push changes if detected
|
||||
#
|
||||
|
||||
local current_dir=$(pwd)
|
||||
local backup_dir="$HOME/projects/backups"
|
||||
github_username=$(git config --global user.name | tr '[:upper:]' '[:lower:]' | tr -d '[:space:]')
|
||||
local commit_message="Backup ~/.zshrc at $(date +'%Y_%m_%d-%H%M%S')"
|
||||
|
||||
# Prompt for GitHub username if not set
|
||||
if [[ -z "$github_username" ]]; then
|
||||
read -p "Enter your GitHub username: " github_username
|
||||
fi
|
||||
|
||||
# Create a backup directory if it doesn't exist
|
||||
mkdir -p "$backup_dir"
|
||||
|
||||
cd "$backup_dir" || return
|
||||
|
||||
# Backup ~/.zshrc with a timestamp
|
||||
local timestamp=$(date +'%Y_%m_%d-%H%M%S')
|
||||
local backup_file="$backup_dir/zshrc_backup_$timestamp"
|
||||
cp "$HOME/.zshrc" "$backup_dir/.zshrc"
|
||||
|
||||
changes=$(git diff --quiet --exit-code -- "$backup_dir" || echo "yes")
|
||||
|
||||
if [[ "$changes" == "yes" ]]; then
|
||||
echo "Changes detected in $backup_dir/.zshrc"
|
||||
cp "$HOME/.zshrc" "$backup_file"
|
||||
git add . > /dev/null 2>&1
|
||||
if git commit -m "$commit_message" > /dev/null 2>&1; then
|
||||
if git push > /dev/null 2>&1; then
|
||||
repo_url="https://github.com/$github_username/backups"
|
||||
echo "Backup successfully pushed to GitHub. View it at: $repo_url"
|
||||
else
|
||||
push_error=$(git push 2>&1)
|
||||
echo "Error: Failed to push backup to GitHub. Error details: $push_error"
|
||||
fi
|
||||
else
|
||||
commit_error=$(git commit -m "$commit_message" 2>&1)
|
||||
echo "Error: Failed to commit changes for backup. Error details: $commit_error"
|
||||
fi
|
||||
else
|
||||
echo "No changes detected in $backup_dir for .zshrc"
|
||||
fi
|
||||
|
||||
cd "$backup_dir" || return
|
||||
git add . > /dev/null 2>&1
|
||||
cd "$current_dir" || return
|
||||
}
|
||||
|
||||
backup_zshrc
|
|
@ -42,6 +42,8 @@ as you want:
|
|||
zstyle ':omz:plugins:nvm' lazy-cmd eslint prettier typescript ...
|
||||
```
|
||||
|
||||
There will be a function `_omz_nvm_load` available to load `nvm` without executing any other trigger command.
|
||||
|
||||
#### `.nvmrc` autoload
|
||||
|
||||
Note: _if used at the same time as `lazy`, `autoload` will start working only after nvm has been lazy-loaded_
|
||||
|
|
|
@ -20,7 +20,7 @@ if [[ -z "$NVM_DIR" ]] || [[ ! -f "$NVM_DIR/nvm.sh" ]]; then
|
|||
return
|
||||
fi
|
||||
|
||||
function _omz_load_nvm_completion {
|
||||
function _omz_nvm_setup_completion {
|
||||
local _nvm_completion
|
||||
# Load nvm bash completion
|
||||
for _nvm_completion in "$NVM_DIR/bash_completion" "$NVM_HOMEBREW/etc/bash_completion.d/nvm"; do
|
||||
|
@ -33,12 +33,12 @@ function _omz_load_nvm_completion {
|
|||
break
|
||||
fi
|
||||
done
|
||||
unfunction _omz_load_nvm_completion
|
||||
unfunction _omz_nvm_setup_completion
|
||||
}
|
||||
|
||||
function _omz_setup_autoload {
|
||||
function _omz_nvm_setup_autoload {
|
||||
if ! zstyle -t ':omz:plugins:nvm' autoload; then
|
||||
unfunction _omz_setup_autoload
|
||||
unfunction _omz_nvm_setup_autoload
|
||||
return
|
||||
fi
|
||||
|
||||
|
@ -68,13 +68,13 @@ function _omz_setup_autoload {
|
|||
add-zsh-hook chpwd load-nvmrc
|
||||
|
||||
load-nvmrc
|
||||
unfunction _omz_setup_autoload
|
||||
unfunction _omz_nvm_setup_autoload
|
||||
}
|
||||
|
||||
if zstyle -t ':omz:plugins:nvm' lazy; then
|
||||
# Call nvm when first using nvm, node, npm, pnpm, yarn, corepack or other commands in lazy-cmd
|
||||
zstyle -a ':omz:plugins:nvm' lazy-cmd nvm_lazy_cmd
|
||||
nvm_lazy_cmd=(nvm node npm npx pnpm pnpx yarn corepack $nvm_lazy_cmd) # default values
|
||||
nvm_lazy_cmd=(_omz_nvm_load nvm node npm npx pnpm pnpx yarn corepack $nvm_lazy_cmd) # default values
|
||||
eval "
|
||||
function $nvm_lazy_cmd {
|
||||
for func in $nvm_lazy_cmd; do
|
||||
|
@ -84,14 +84,16 @@ if zstyle -t ':omz:plugins:nvm' lazy; then
|
|||
done
|
||||
# Load nvm if it exists in \$NVM_DIR
|
||||
[[ -f \"\$NVM_DIR/nvm.sh\" ]] && source \"\$NVM_DIR/nvm.sh\"
|
||||
_omz_load_nvm_completion
|
||||
_omz_setup_autoload
|
||||
_omz_nvm_setup_completion
|
||||
_omz_nvm_setup_autoload
|
||||
if [[ \"\$0\" != _omz_nvm_load ]]; then
|
||||
\"\$0\" \"\$@\"
|
||||
fi
|
||||
}
|
||||
"
|
||||
unset nvm_lazy_cmd
|
||||
else
|
||||
source "$NVM_DIR/nvm.sh"
|
||||
_omz_load_nvm_completion
|
||||
_omz_setup_autoload
|
||||
_omz_nvm_setup_completion
|
||||
_omz_nvm_setup_autoload
|
||||
fi
|
||||
|
|
|
@ -16,9 +16,10 @@ plugins=(... terraform)
|
|||
## Aliases
|
||||
|
||||
| Alias | Command |
|
||||
|--------|----------------------------|
|
||||
|---------|----------------------------------|
|
||||
| `tf` | `terraform` |
|
||||
| `tfa` | `terraform apply` |
|
||||
| `tfaa` | `terraform apply -auto-approve` |
|
||||
| `tfc` | `terraform console` |
|
||||
| `tfd` | `terraform destroy` |
|
||||
| `tff` | `terraform fmt` |
|
||||
|
|
|
@ -17,6 +17,7 @@ function tf_version_prompt_info() {
|
|||
|
||||
alias tf='terraform'
|
||||
alias tfa='terraform apply'
|
||||
alias tfaa='terraform apply -auto-approve'
|
||||
alias tfc='terraform console'
|
||||
alias tfd='terraform destroy'
|
||||
alias tff='terraform fmt'
|
||||
|
|
|
@ -51,6 +51,7 @@ Available search contexts are:
|
|||
| `packagist` | `https://packagist.org/?query=` |
|
||||
| `gopkg` | `https://pkg.go.dev/search?m=package&q=` |
|
||||
| `chatgpt` | `https://chatgpt.com/?q=` |
|
||||
| `reddit` | `https://www.reddit.com/search/?q=` |
|
||||
|
||||
Also there are aliases for bang-searching DuckDuckGo:
|
||||
|
||||
|
|
|
@ -32,6 +32,7 @@ function web_search() {
|
|||
packagist "https://packagist.org/?query="
|
||||
gopkg "https://pkg.go.dev/search?m=package&q="
|
||||
chatgpt "https://chatgpt.com/?q="
|
||||
reddit "https://www.reddit.com/search/?q="
|
||||
)
|
||||
|
||||
# check whether the search engine is supported
|
||||
|
@ -85,6 +86,7 @@ alias npmpkg='web_search npmpkg'
|
|||
alias packagist='web_search packagist'
|
||||
alias gopkg='web_search gopkg'
|
||||
alias chatgpt='web_search chatgpt'
|
||||
alias reddit='web_search reddit'
|
||||
|
||||
#add your own !bang searches here
|
||||
alias wiki='web_search duckduckgo \!w'
|
||||
|
|
|
@ -30,8 +30,9 @@ local return_code="%(?..%F{red}%? ↵%f)"
|
|||
local user_host="${PR_USER}%F{cyan}@${PR_HOST}"
|
||||
local current_dir="%B%F{blue}%~%f%b"
|
||||
local git_branch='$(git_prompt_info)'
|
||||
local venv_prompt='$(virtualenv_prompt_info)'
|
||||
|
||||
PROMPT="╭─${user_host} ${current_dir} \$(ruby_prompt_info) ${git_branch}
|
||||
PROMPT="╭─${venv_prompt}${user_host} ${current_dir} \$(ruby_prompt_info) ${git_branch}
|
||||
╰─$PR_PROMPT "
|
||||
RPROMPT="${return_code}"
|
||||
|
||||
|
@ -39,5 +40,7 @@ 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"
|
||||
ZSH_THEME_VIRTUALENV_PREFIX="%F{red}("
|
||||
ZSH_THEME_VIRTUALENV_SUFFIX=")%f "
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue