diff options
| author | srdusr <trevorgray@srdusr.com> | 2023-11-12 22:47:50 +0200 |
|---|---|---|
| committer | srdusr <trevorgray@srdusr.com> | 2023-11-12 22:47:50 +0200 |
| commit | cb95bc65a9eb1454871d248a796e6a4856772ef3 (patch) | |
| tree | 827ec4dc96b61ab080348f08dbe5f3a46ea68b16 /.config/zsh | |
| parent | b0aa918ab78ff7e4483376c29635d15c335b0766 (diff) | |
| download | dotfiles-cb95bc65a9eb1454871d248a796e6a4856772ef3.tar.gz dotfiles-cb95bc65a9eb1454871d248a796e6a4856772ef3.zip | |
Improved gsp function
Diffstat (limited to '.config/zsh')
| -rw-r--r-- | .config/zsh/.zshrc | 35 |
1 files changed, 23 insertions, 12 deletions
diff --git a/.config/zsh/.zshrc b/.config/zsh/.zshrc index b0a6c7a..8393597 100644 --- a/.config/zsh/.zshrc +++ b/.config/zsh/.zshrc @@ -376,8 +376,8 @@ function chpwd() { # Call the function to set Git environment variables when the shell starts up set_git_env_vars -function gsp -{ + +function gsp() { # Config file for subtrees # # Format: @@ -385,14 +385,19 @@ function gsp # # Lines starting with '#' will be ignored GIT_SUBTREE_FILE="$PWD/.gitsubtrees" - if [ ! -f $GIT_SUBTREE_FILE ]; then - echo "Nothing to do - file <`basename $GIT_SUBTREE_FILE`> does not exist." + if [ ! -f "$GIT_SUBTREE_FILE" ]; then + echo "Nothing to do - file <$GIT_SUBTREE_FILE> does not exist." + return + fi + + if ! command -v config &> /dev/null; then + echo "Error: 'config' command not found. Make sure it's available in your PATH." return fi OLD_IFS=$IFS IFS=$'\n' - for LINE in $(cat $GIT_SUBTREE_FILE); do + for LINE in $(cat "$GIT_SUBTREE_FILE"); do # Skip lines starting with '#'. if [[ $LINE = \#* ]]; then @@ -400,14 +405,20 @@ function gsp fi # Parse the current line. - PREFIX=`echo $LINE | cut -d';' -f 1` - REMOTE=`echo $LINE | cut -d';' -f 2` - BRANCH=`echo $LINE | cut -d';' -f 3` - - # Push to the remote. - echo "config subtree pull --prefix=$PREFIX $REMOTE $BRANCH" - config subtree pull --prefix=$PREFIX $REMOTE $BRANCH + PREFIX=$(echo "$LINE" | cut -d';' -f 1) + REMOTE=$(echo "$LINE" | cut -d';' -f 2) + BRANCH=$(echo "$LINE" | cut -d';' -f 3) + + # Pull from the remote. + echo "Executing: git subtree pull --prefix=$PREFIX $REMOTE $BRANCH" + if git subtree pull --prefix="$PREFIX" "$REMOTE" "$BRANCH"; then + echo "Subtree pull successful for $PREFIX." + else + echo "Error: Subtree pull failed for $PREFIX." + fi done + + IFS=$OLD_IFS } # Print previous command into a file |
