Skip to content

Commit

Permalink
Support <&&> Match
Browse files Browse the repository at this point in the history
  • Loading branch information
xujinkai committed Nov 1, 2019
1 parent 38ee70d commit dcf7bca
Showing 3 changed files with 22 additions and 12 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -25,8 +25,9 @@ Plus, `%DIR%` stands for current folder.
### Match

- If not null, checks if current folder have the name (file or directory)
- Starts by ! for NOT have the name
- use ? and * for wildcard
- Splits conditions by **<&&>**
- Starts by **!** for reverse condition
- Use **?** and ***** for wildcard

### Icon

20 changes: 12 additions & 8 deletions ShellCommand/DataModel/DirectoryCommand.cs
Original file line number Diff line number Diff line change
@@ -51,16 +51,20 @@ public bool IsMatch(string workingDir)
if (string.IsNullOrEmpty(Match))
return true;

bool reverse = false;
string pattern = Match;
if (Match.StartsWith("!"))
bool result = true;
foreach (var split in Match.Split(new string[] { "<&&>" }, StringSplitOptions.RemoveEmptyEntries))
{
reverse = true;
pattern = Match.Substring(1);
var pattern = split;
bool reverse = false;
if (pattern.StartsWith("!"))
{
reverse = true;
pattern = pattern.Substring(1);
}
var exist = Directory.GetFiles(workingDir, pattern).Any() || Directory.GetDirectories(workingDir, pattern).Any();
result &= exist ^ reverse;
}

var exist = Directory.GetFiles(workingDir, pattern).Any() || Directory.GetDirectories(workingDir, pattern).Any();
return exist ^ reverse;
return result;
}

public ToolStripItem ToMenuItem(string workingDir)
9 changes: 7 additions & 2 deletions ShellCommand/global.template.shellcommand.yaml
Original file line number Diff line number Diff line change
@@ -14,16 +14,21 @@ GlobalCommands:
Match: .gitmodules
Icon: "%PROGRAMFILES%/Git/git-cmd.exe"

- Name: Create README.md
Command: cmd /c copy nul README.md
Match: ".git<&&>!README.md"
Icon: "%SystemRoot%/System32/Shell32.dll?70"

- Name: ---

- Name: Open Command Window Here(&C)
Command: cmd
Icon: C:/WIndows/System32/cmd.exe
Icon: "%SystemRoot%/System32/cmd.exe"

- Name: Open Command Window Here (Administrator)(&A)
Command: cmd /K "cd /d ""%DIR%"""
RunAsAdmin: true
Icon: C:/WIndows/System32/cmd.exe
Icon: "%SystemRoot%/System32/cmd.exe"

- Name: ---

0 comments on commit dcf7bca

Please sign in to comment.