Skip to content

Commit

Permalink
feat(update-sln): add support for glob patterns (#16)
Browse files Browse the repository at this point in the history
* add support for recursive evaluation of solution files (glob patterns)
* set missing execution bit on:
  - la
  - ll
  - lla
  - lsp

Example of glob pattern:

update-sln **/*.sln # recursively update all solutions in the current folder
  • Loading branch information
dmccaffery authored May 9, 2019
1 parent 576ef6b commit b4c4b7e
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/bashrc
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export CLR_SSH_PROMPT=$CLR_BRIGHT_MAGENTA # COLOR OF THE PROMPT FOR SSH
shopt -s checkwinsize # check window size on script exit
shopt -s cdable_vars # enable change directory to a variable value
shopt -s extglob # enable extended glob patterns
shopt -s globstar # enable glob ** expansion

# enable colors for various commands
export TERM=xterm-256color
Expand Down
Empty file modified src/scripts/la
100644 → 100755
Empty file.
Empty file modified src/scripts/ll
100644 → 100755
Empty file.
Empty file modified src/scripts/lla
100644 → 100755
Empty file.
Empty file modified src/scripts/lsp
100644 → 100755
Empty file.
34 changes: 30 additions & 4 deletions src/scripts/update-sln
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,42 @@

__contains() { for item in "${@:2}"; do [[ "$item" == "$1" ]] && return 0; done; return 1; }

for SLN in *.sln; do
EXISTING=($(dotnet sln "$SLN" list))
SOLUTIONS=($@)

CURRENT_PATH=$(pwd)

if [ ${#SOLUTIONS[@]} -eq 0 ]; then
SOLUTIONS=(*.sln)
fi

for solution in "${SOLUTIONS[@]}"; do
if [ ! -f "$solution" ]; then
echo "ERROR: $solution does not exist; skipping..."
echo

continue
fi

solution="./$solution"

basepath="${solution%/*}"
name="${solution##*/}"

echo "Checking solution: $name"

pushd "$basepath" 1>/dev/null

EXISTING=($(dotnet sln "$name" list))
EXISTING=("${EXISTING[@]:2}")
DISCOVERED=($(find * -name '*.csproj' ! -path '*/bin/*' ! -path '*/obj/*' ! -path '*/shared/*' ))

for existing in "${EXISTING[@]}"; do
__contains $existing "${DISCOVERED[@]}" || dotnet sln "$SLN" remove "$existing"
__contains $existing "${DISCOVERED[@]}" || dotnet sln "$name" remove "$existing"
done

for discovered in "${DISCOVERED[@]}"; do
__contains $discovered "${EXISTING[@]}" || dotnet sln "$SLN" add "$discovered"
__contains $discovered "${EXISTING[@]}" || dotnet sln "$name" add "$discovered"
done

popd 1>/dev/null
done

0 comments on commit b4c4b7e

Please sign in to comment.