mirror of
https://github.com/nsnail/dot.git
synced 2025-04-14 09:32:49 +08:00
chore: 🔨 删除无用文件 (#14)
This commit is contained in:
parent
19f3405a36
commit
d50e5b2d27
@ -1,12 +0,0 @@
|
||||
{
|
||||
"version": 1,
|
||||
"isRoot": true,
|
||||
"tools": {
|
||||
"dotnet-t4": {
|
||||
"version": "2.3.1",
|
||||
"commands": [
|
||||
"t4"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
111
src/Git/Main.cs
111
src/Git/Main.cs
@ -1,111 +0,0 @@
|
||||
using System.Diagnostics;
|
||||
using System.Text;
|
||||
using NSExt.Extensions;
|
||||
|
||||
namespace Dot.Git;
|
||||
|
||||
public class Main : ToolBase<Option>
|
||||
{
|
||||
private const int _POS_Y_MSG = 74; //git command rsp 显示的位置 y
|
||||
private const int _POST_Y_LOADING = 70; //loading 动画显示的位置 y
|
||||
private const int _REP_PATH_LENGTH_LIMIT = 32; //仓库路径长度显示截断阈值
|
||||
private (int x, int y) _cursorPosBackup; //光标位置备份
|
||||
private readonly Encoding _gitOutputEnc; //git command rsp 编码
|
||||
private List<string> _repoPathList; //仓库目录列表
|
||||
|
||||
|
||||
public Main(Option opt) : base(opt)
|
||||
{
|
||||
_gitOutputEnc = Encoding.GetEncoding(Opt.GitOutputEncoding);
|
||||
if (!Directory.Exists(Opt.Path))
|
||||
throw new ArgumentException(nameof(Opt.Path) //
|
||||
, string.Format(Str.PathNotFound, Opt.Path));
|
||||
}
|
||||
|
||||
|
||||
private async ValueTask DirHandle(string dir, CancellationToken cancelToken)
|
||||
{
|
||||
var row = _repoPathList.FindIndex(x => x == dir); // 行号
|
||||
var tAnimate = LoadingAnimate(_POST_Y_LOADING, _cursorPosBackup.y + row, out var cts);
|
||||
|
||||
// 打印 git command rsp
|
||||
void ExecRspReceived(object sender, DataReceivedEventArgs e)
|
||||
{
|
||||
if (e.Data is null) return;
|
||||
var msg = Encoding.UTF8.GetString(_gitOutputEnc.GetBytes(e.Data));
|
||||
ConcurrentWrite(_POS_Y_MSG, _cursorPosBackup.y + row, new string(' ', Console.WindowWidth - _POS_Y_MSG));
|
||||
ConcurrentWrite(_POS_Y_MSG, _cursorPosBackup.y + row, msg);
|
||||
}
|
||||
|
||||
// 启动git进程
|
||||
{
|
||||
var startInfo = new ProcessStartInfo {
|
||||
CreateNoWindow = true
|
||||
, WorkingDirectory = dir
|
||||
, FileName = "git"
|
||||
, Arguments = Opt.Args
|
||||
, UseShellExecute = false
|
||||
, RedirectStandardOutput = true
|
||||
, RedirectStandardError = true
|
||||
};
|
||||
using var p = Process.Start(startInfo);
|
||||
p!.OutputDataReceived += ExecRspReceived;
|
||||
p.ErrorDataReceived += ExecRspReceived;
|
||||
p.BeginOutputReadLine();
|
||||
p.BeginErrorReadLine();
|
||||
await p.WaitForExitAsync();
|
||||
}
|
||||
|
||||
cts.Cancel();
|
||||
await tAnimate;
|
||||
cts.Dispose();
|
||||
}
|
||||
|
||||
private void StashCurorPos()
|
||||
{
|
||||
_cursorPosBackup = Console.GetCursorPosition();
|
||||
}
|
||||
|
||||
|
||||
public override async Task Run()
|
||||
{
|
||||
// 查找git仓库目录
|
||||
{
|
||||
Console.Write(Str.FindGitReps, Opt.Path);
|
||||
StashCurorPos();
|
||||
|
||||
var tAnimate = LoadingAnimate(_cursorPosBackup.x, _cursorPosBackup.y, out var cts);
|
||||
_repoPathList = Directory.GetDirectories(Opt.Path, ".git" //
|
||||
, new EnumerationOptions //
|
||||
{
|
||||
MaxRecursionDepth = Opt.MaxRecursionDepth
|
||||
, RecurseSubdirectories = true
|
||||
, IgnoreInaccessible = true
|
||||
, AttributesToSkip = FileAttributes.ReparsePoint
|
||||
})
|
||||
.Select(x => Directory.GetParent(x)!.FullName)
|
||||
.ToList();
|
||||
cts.Cancel();
|
||||
await tAnimate;
|
||||
cts.Dispose();
|
||||
}
|
||||
|
||||
// 打印git仓库目录
|
||||
{
|
||||
Console.WriteLine(Str.Ok);
|
||||
StashCurorPos();
|
||||
|
||||
var i = 0;
|
||||
Console.WriteLine( //
|
||||
string.Join(Environment.NewLine
|
||||
, _repoPathList.Select(
|
||||
x => $"{++i}: {new DirectoryInfo(x).Name.Sub(0, _REP_PATH_LENGTH_LIMIT)}"))
|
||||
//
|
||||
);
|
||||
}
|
||||
|
||||
// 并行执行git命令
|
||||
await Parallel.ForEachAsync(_repoPathList, DirHandle);
|
||||
Console.SetCursorPosition(_cursorPosBackup.x, _cursorPosBackup.y + _repoPathList.Count);
|
||||
}
|
||||
}
|
@ -1,19 +0,0 @@
|
||||
namespace Dot.Git;
|
||||
|
||||
[Verb("git", HelpText = nameof(Str.GitTool), ResourceType = typeof(Str))]
|
||||
public class Option : OptionBase
|
||||
{
|
||||
[Option('a', "args", HelpText = nameof(Str.GitArgs), Default = "status", ResourceType = typeof(Str))]
|
||||
public string Args { get; set; }
|
||||
|
||||
[Option('e', "git-output-encoding", HelpText = nameof(Str.GitOutputEncoding), Default = "utf-8"
|
||||
, ResourceType = typeof(Str))]
|
||||
public string GitOutputEncoding { get; set; }
|
||||
|
||||
[Option('d', "max-recursion-depth", HelpText = nameof(Str.MaxRecursionDepth), Default = int.MaxValue
|
||||
, ResourceType = typeof(Str))]
|
||||
public int MaxRecursionDepth { get; set; }
|
||||
|
||||
[Value(0, HelpText = nameof(Str.FolderPath), Default = ".", ResourceType = typeof(Str))]
|
||||
public string Path { get; set; }
|
||||
}
|
@ -1,68 +0,0 @@
|
||||
using System.Text.Json;
|
||||
using NSExt.Extensions;
|
||||
using TextCopy;
|
||||
|
||||
namespace Dot.Json;
|
||||
|
||||
public class Main : ToolBase<Option>
|
||||
{
|
||||
private readonly object _inputObj;
|
||||
|
||||
public Main(Option opt) : base(opt)
|
||||
{
|
||||
var inputText = ClipboardService.GetText();
|
||||
if (inputText.NullOrWhiteSpace()) throw new ArgumentException(Str.InputTextIsEmpty);
|
||||
|
||||
try {
|
||||
_inputObj = inputText.Object<object>();
|
||||
}
|
||||
catch (JsonException) {
|
||||
try {
|
||||
inputText = UnescapeString(inputText);
|
||||
_inputObj = inputText.Object<object>();
|
||||
return;
|
||||
}
|
||||
catch (JsonException) { }
|
||||
|
||||
throw new ArgumentException(Str.InvalidJsonString);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private async Task<string> ConvertToString()
|
||||
{
|
||||
var ret = await JsonCompress();
|
||||
ret = ret.Replace("\"", "\\\"");
|
||||
return ret;
|
||||
}
|
||||
|
||||
private Task<string> JsonCompress()
|
||||
{
|
||||
var ret = _inputObj.Json();
|
||||
return Task.FromResult(ret);
|
||||
}
|
||||
|
||||
private Task<string> JsonFormat()
|
||||
{
|
||||
var ret = _inputObj.Json(true);
|
||||
return Task.FromResult(ret);
|
||||
}
|
||||
|
||||
private static string UnescapeString(string text)
|
||||
{
|
||||
return text.Replace("\\\"", "\"");
|
||||
}
|
||||
|
||||
public override async Task Run()
|
||||
{
|
||||
string result = null;
|
||||
if (Opt.Compress)
|
||||
result = await JsonCompress();
|
||||
else if (Opt.ConvertToString)
|
||||
result = await ConvertToString();
|
||||
else if (Opt.Format) result = await JsonFormat();
|
||||
|
||||
if (result.NullOrWhiteSpace()) return;
|
||||
await ClipboardService.SetTextAsync(result!);
|
||||
}
|
||||
}
|
@ -1,15 +0,0 @@
|
||||
namespace Dot.Json;
|
||||
|
||||
[Verb("json", HelpText = nameof(Str.Json), ResourceType = typeof(Str))]
|
||||
public class Option : OptionBase
|
||||
{
|
||||
[Option('c', "compress", HelpText = nameof(Str.CompressJson), Default = false, ResourceType = typeof(Str))]
|
||||
public bool Compress { get; set; }
|
||||
|
||||
|
||||
[Option('s', "convert-to-string", HelpText = nameof(Str.FormatJson), Default = false, ResourceType = typeof(Str))]
|
||||
public bool ConvertToString { get; set; }
|
||||
|
||||
[Option('f', "format", HelpText = nameof(Str.FormatJson), Default = true, ResourceType = typeof(Str))]
|
||||
public bool Format { get; set; }
|
||||
}
|
@ -1,86 +0,0 @@
|
||||
<#@ template language="C#" #>
|
||||
<#@ assembly name="System.Xml" #>
|
||||
<#@ output encoding="utf-8" extension="Designer.cs" #>
|
||||
<#@ import namespace="System.Xml" #>
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// This code was generated by a tool.
|
||||
//
|
||||
// Changes to this file may cause incorrect behavior and will be lost if
|
||||
// the code is regenerated.
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace Dot.Lang {
|
||||
using System;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// A strongly-typed resource class, for looking up localized strings, etc.
|
||||
/// </summary>
|
||||
// This class was auto-generated by the StronglyTypedResourceBuilder
|
||||
// class via a tool like ResGen or Visual Studio.
|
||||
// To add or remove a member, edit your .ResX file then rerun ResGen
|
||||
// with the /str option, or rebuild your VS project.
|
||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
||||
public class Str {
|
||||
|
||||
private static global::System.Resources.ResourceManager resourceMan;
|
||||
|
||||
private static global::System.Globalization.CultureInfo resourceCulture;
|
||||
|
||||
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
|
||||
internal Str() {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the cached ResourceManager instance used by this class.
|
||||
/// </summary>
|
||||
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
|
||||
public static global::System.Resources.ResourceManager ResourceManager {
|
||||
get {
|
||||
if (object.ReferenceEquals(resourceMan, null)) {
|
||||
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Dot.Lang.Str", typeof(Str).Assembly);
|
||||
resourceMan = temp;
|
||||
}
|
||||
return resourceMan;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Overrides the current thread's CurrentUICulture property for all
|
||||
/// resource lookups using this strongly typed resource class.
|
||||
/// </summary>
|
||||
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
|
||||
public static global::System.Globalization.CultureInfo Culture {
|
||||
get {
|
||||
return resourceCulture;
|
||||
}
|
||||
set {
|
||||
resourceCulture = value;
|
||||
}
|
||||
}
|
||||
|
||||
<#
|
||||
var xml = new XmlDocument();
|
||||
xml.Load("Str.resx");
|
||||
foreach (XmlNode data in xml.SelectNodes("//root/data")) {
|
||||
#>
|
||||
/// <summary>
|
||||
/// <#= data.SelectSingleNode("value").InnerText #>
|
||||
/// </summary>
|
||||
public static string <#= data.Attributes["name"].Value #> {
|
||||
get {
|
||||
return ResourceManager.GetString("<#= data.Attributes["name"].Value #>", resourceCulture);
|
||||
}
|
||||
}
|
||||
<#
|
||||
}
|
||||
#>
|
||||
|
||||
}
|
||||
}
|
@ -1,7 +0,0 @@
|
||||
namespace Dot;
|
||||
|
||||
public abstract class OptionBase : IOption
|
||||
{
|
||||
[Option('k', "keep-session", HelpText = nameof(Str.KeepSession), Default = false, ResourceType = typeof(Str))]
|
||||
public virtual bool KeepSession { get; set; }
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user