From 1c18da8d9edf209a29b88cf7462b39acb4888ca1 Mon Sep 17 00:00:00 2001 From: mxochicale Date: Sat, 31 Aug 2024 22:18:41 +0100 Subject: [PATCH] renames bashrc/append_tools_to_bashrc.bash and adds gmc (reference: https://x.com/karpathy/status/1827810695658029262) --- bashrc/README.md | 39 ++------ bashrc/append_aliases_to_bashrc.bash | 39 -------- bashrc/append_tools_to_bashrc.bash | 134 +++++++++++++++++++++++++++ 3 files changed, 143 insertions(+), 69 deletions(-) delete mode 100644 bashrc/append_aliases_to_bashrc.bash create mode 100644 bashrc/append_tools_to_bashrc.bash diff --git a/bashrc/README.md b/bashrc/README.md index cd79a58..a44f2aa 100644 --- a/bashrc/README.md +++ b/bashrc/README.md @@ -1,44 +1,23 @@ # .bashrc -## Dependencies -xsel to copy and paste from the terminal +## Adding aliases and functions to .bashrc file ``` -sudo apt install xsel +cd +wget https://raw.githubusercontent.com/mxochicale/tools/master/bashrc/append_tools_to_bashrc.bash ``` -## Add my alias in the .bashrc file -The following is list of personal aliases that are helping me -to move easily in the GNU/Linux terminal. - -Lines added to the ".bashrc" file +* Append lines to bashrc: ``` -#------------------- -# Personal Aliases -#------------------- - -alias c='clear' -alias h='history' -alias ll="ls -liah" ##alias ll='ls -alF' -alias la='ls -A' -alias l='ls -CF' -alias pwdc='pwd | tr " " " " | xsel -bi' -alias datec='date | tr " " " " | xsel -bi' -alias ..='cd ..' +bash append_tools_to_bashrc.bash ``` -### Adding aliases and functions to .bashrc file +* Reload bashrc file ``` -cd -wget https://raw.githubusercontent.com/mxochicale/tools/master/bashrc/append_aliases_to_bashrc.bash +source ~/.bashrc ``` -append lines to bashrc: +* Remove bash file ``` -bash append_aliases_to_bashrc.bash +rm append_tools_to_bashrc.bash ``` - -Reload bashrc file -``` -source ~/.bashrc ``` - diff --git a/bashrc/append_aliases_to_bashrc.bash b/bashrc/append_aliases_to_bashrc.bash deleted file mode 100644 index 6489ae9..0000000 --- a/bashrc/append_aliases_to_bashrc.bash +++ /dev/null @@ -1,39 +0,0 @@ -#!/bin/bash - -sudo apt install xsel - -cd -{ -echo '' -echo '' -echo '#============================================================' -echo '#' -echo '# ALIASES AND FUNCTIONS' -echo '#' -echo '# Learn more about aliases and functions at' -echo '# http://tldp.org/LDP/abs/html/sample-bashrc.html' -echo '#' -echo '#' -echo '#' -echo '#============================================================' -echo '' -echo '' -echo '#-------------------' -echo '# Personnal Aliases' -echo '#-------------------' -echo ' ' -echo "alias c='clear' " -echo "alias h='history' " -echo "alias ll=\"ls -liah\" " -echo "alias ..='cd ..' " -echo "alias pwdc='pwd | tr \" \" \" \" | xsel -bi' " -echo "alias datec='date | tr \" \" \" \" | xsel -bi' " -echo '' -echo '' -echo '' -echo '' -} >> .bashrc - - -#reload bashrc file -source ~/.bashrc diff --git a/bashrc/append_tools_to_bashrc.bash b/bashrc/append_tools_to_bashrc.bash new file mode 100644 index 0000000..49c018a --- /dev/null +++ b/bashrc/append_tools_to_bashrc.bash @@ -0,0 +1,134 @@ +#!/bin/bash + +sudo apt install xsel + +#aliases and fuctions +cd +{ +echo '' +echo '' +echo '#============================================================' +echo '#' +echo '# ALIASES AND FUNCTIONS' +echo '#' +echo '# Learn more about aliases and functions at' +echo '# http://tldp.org/LDP/abs/html/sample-bashrc.html' +echo '#' +echo '#' +echo '#' +echo '#============================================================' +echo '' +echo '' +echo '#-------------------' +echo '# Personnal Aliases' +echo '#-------------------' +echo ' ' +echo "alias c='clear' " +echo "alias h='history' " +echo "alias ll=\"ls -liah\" " +echo "alias ..='cd ..' " +echo "alias pwdc='pwd | tr \" \" \" \" | xsel -bi' " +echo "alias datec='date | tr \" \" \" \" | xsel -bi' " +echo '' +echo '' +echo '' +echo '' +} >> .bashrc + + + +cd +{ +echo '' +echo '' +echo '#============================================================' +echo '#' +echo '# AI-powered Git Commit Function `gcm`' +echo '# Install ollama `curl -fsSL https://ollama.com/install.sh | sh`' +echo '# gcm' +echo '# 1) gets the current staged changed diff' +echo '# 2) sends them to an LLM to write the git commit message' +echo '# 3) allows you to easily accept, edit, regenerate, cancel' +echo '# based on https://gist.github.com/karpathy/1dd0294ef9567971c1e4348a90d69285' +echo '# reference https://gist.github.com/nikolaydubina/12e3c692eeb3a651579c9f6c25d024f8' +echo '' +echo '#============================================================' +echo '' +echo 'gcm() {' +echo ' # Function to generate commit message' +echo ' generate_commit_message() {' +echo ' git diff --cached | ollama run moondream "' +echo 'Below is a diff of all staged changes, coming from the command:' +echo '' +echo '\`\`\`' +echo 'git diff --cached' +echo '\`\`\`' +echo '' +echo 'Please generate a concise, one-line commit message for these changes."' +echo ' }' +echo '' +echo '' +echo ' # Function to read user input compatibly with both Bash and Zsh' +echo ' read_input() {' +echo ' if [ -n "$ZSH_VERSION" ]; then' +echo ' echo -n "$1"' +echo ' read -r REPLY' +echo ' else' +echo ' read -p "$1" -r REPLY' +echo ' fi' +echo ' }' +echo '' +echo ' # Main script' +echo ' echo "Generating..."' +echo ' commit_message=$(generate_commit_message)' +echo '' +echo ' while true; do' +echo ' echo -e "\nProposed commit message:"' +echo ' echo "$commit_message"' +echo '' +echo ' read_input "Do you want to (a)ccept, (e)dit, (r)egenerate, or (c)ancel? "' +echo ' choice=$REPLY' +echo '' +echo ' case "$choice" in' +echo ' a|A )' +echo ' if git commit -m "$commit_message"; then' +echo ' echo "Changes committed successfully!"' +echo ' return 0' +echo ' else' +echo ' echo "Commit failed. Please check your changes and try again."' +echo ' return 1' +echo ' fi' +echo ' ;;' +echo ' e|E )' +echo ' read_input "Enter your commit message: "' +echo ' commit_message=$REPLY' +echo ' if [ -n "$commit_message" ] && git commit -m "$commit_message"; then' +echo ' echo "Changes committed successfully with your message!"' +echo ' return 0' +echo ' else' +echo ' echo "Commit failed. Please check your message and try again."' +echo ' return 1' +echo ' fi' +echo ' ;;' +echo ' r|R )' +echo ' echo "Regenerating commit message..."' +echo ' commit_message=$(generate_commit_message)' +echo ' ;;' +echo ' c|C )' +echo ' echo "Commit cancelled."' +echo ' return 1' +echo ' ;;' +echo ' * )' +echo ' echo "Invalid choice. Please try again."' +echo ' ;;' +echo ' esac' +echo ' done' +echo '}' +echo '' +echo '' +} >> .bashrc + + + +#reload bashrc file +source ~/.bashrc