-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhello.txt
More file actions
494 lines (431 loc) · 16 KB
/
hello.txt
File metadata and controls
494 lines (431 loc) · 16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
===== ./bash-tools/bashrc.sh =====
# ────────────────────────────────────────────────────────────────
# 📦 TOOLS (1: structure, 2: lister, 3: concat, 4: github, 5: quit)
# ────────────────────────────────────────────────────────────────
# Helpers ---------------------------------------------------------
_str_to_array() { # "a b c" -> ["a","b","c"]
local s="$1"; local -n _out="$2"
_out=(); for d in $s; do _out+=("$d"); done
}
_build_types_expr() { # map types connus + globs -> expr find
local -a in_patterns=("$@")
local -a expr=()
for p in "${in_patterns[@]}"; do
case "$p" in
js) expr+=( -iname '*.js' -o -iname '*.mjs' -o -iname '*.cjs' -o ) ;;
ts) expr+=( -iname '*.ts' -o -iname '*.tsx' -o ) ;;
py) expr+=( -iname '*.py' -o ) ;;
sh) expr+=( -iname '*.sh' -o ) ;;
md) expr+=( -iname '*.md' -o -iname '*.markdown' -o ) ;;
docker)
expr+=(
-iname 'Dockerfile' -o
-iname 'Dockerfile.*' -o
-iname '*.dockerfile' -o
-iname '.dockerignore' -o
-iname 'docker-compose*.yml' -o
-iname 'docker-compose*.yaml' -o
-iname 'compose.yml' -o
-iname 'compose.yaml' -o
-path '*/docker/*' -o
)
;;
*) expr+=( -iname "$p" -o ) ;; # glob brut tel quel (ex: *.yml, Makefile)
esac
done
[[ ${#expr[@]} -gt 0 && "${expr[-1]}" == "-o" ]] && unset 'expr[-1]'
printf '%s\n' "${expr[@]}"
}
_build_prune_expr() { # "node_modules .git dist" -> expr prune robuste
local ignores="$1"
local -a ig=(); _str_to_array "$ignores" ig
local -a prune=()
for d in "${ig[@]}"; do
d="${d%/}" # enlève trailing slash éventuel
[[ -z "$d" ]] && continue
# On match le dossier et tout son contenu, insensible à la casse.
prune+=( -ipath "*/$d" -o -ipath "*/$d/*" -o )
done
[[ ${#prune[@]} -gt 0 ]] && unset 'prune[-1]'
printf '%s\n' "${prune[@]}"
}
_find_files() { # uses arrays; no eval
local ignores="$1"; shift
local -a types_expr=("$@")
local -a prune_expr=(); mapfile -t prune_expr < <(_build_prune_expr "$ignores")
if ((${#prune_expr[@]})); then
# -prune bloque la descente; '-o' passe à la branche fichiers
find . \( "${prune_expr[@]}" \) -prune -o -type f \( "${types_expr[@]}" \) -print0
else
find . -type f \( "${types_expr[@]}" \) -print0
fi
}
_print_structure() {
local ignores="$1"
local -a prune_expr=(); mapfile -t prune_expr < <(_build_prune_expr "$ignores")
if ((${#prune_expr[@]})); then
find . \( "${prune_expr[@]}" \) -prune -o -print \
| awk -F/ '{
indent=""; for(i=2;i<NF;i++) indent=indent"│ ";
if (NF>1) print indent "├── " $NF; else print $0;
}'
else
find . -print \
| awk -F/ '{
indent=""; for(i=2;i<NF;i++) indent=indent"│ ";
if (NF>1) print indent "├── " $NF; else print $0;
}'
fi
}
_list_files() {
local ignores="$1"; shift
local outfile="$1"; shift
local -a patterns=("$@")
mapfile -t types_expr < <(_build_types_expr "${patterns[@]}")
if ((${#types_expr[@]}==0)); then echo "❌ Aucun motif/type."; return 1; fi
: > "$outfile"
while IFS= read -r -d $'\0' f; do
printf '%s\n' "$f" >> "$outfile"
done < <(_find_files "$ignores" "${types_expr[@]}")
echo "✅ Liste écrite → $outfile"
}
_concat_files() {
local ignores="$1"; shift
local outfile="$1"; shift
local -a patterns=("$@")
mapfile -t types_expr < <(_build_types_expr "${patterns[@]}")
if ((${#types_expr[@]}==0)); then echo "❌ Aucun motif/type."; return 1; fi
: > "$outfile"
declare -A seen
while IFS= read -r -d $'\0' f; do
[[ -n "${seen[$f]}" ]] && continue
seen[$f]=1
{
echo "===== $f ====="
cat "$f"
echo
} >> "$outfile"
done < <(_find_files "$ignores" "${types_expr[@]}")
echo "✅ Concat terminé → $outfile"
}
# Menu ------------------------------------------------------------
tools() {
run_choice() {
case "$1" in
1)
echo -n "🧹 Dossiers à ignorer pour la STRUCTURE (ex: node_modules .git dist) : "
read ignores
echo "📁 Génération de structure.txt (ignores: ${ignores:-aucun})..."
_print_structure "$ignores" > structure.txt
echo "✅ structure.txt prêt"
;;
2)
echo "🔎 Lister des fichiers par types/globs"
echo " Types connus: js py sh md ts docker | Globs: *.tsx *.yml Dockerfile Makefile"
echo -n " Motifs/types (séparés par espaces) : "
read line; [[ -z "$line" ]] && { echo "❌ Aucun motif."; return; }
read -r -a patterns <<< "$line"
echo -n "🧹 Dossiers à ignorer (vide = aucun) : "
read ignores
echo -n "📄 Nom du fichier de sortie (défaut: liste.txt) : "
read outfile; [[ -z "$outfile" ]] && outfile="liste.txt"
_list_files "$ignores" "$outfile" "${patterns[@]}"
;;
3)
echo "📚 Concaténer des fichiers par types/globs"
echo " Types connus: js py sh md ts docker | Globs: *.tsx *.yml Dockerfile Makefile"
echo -n " Motifs/types (séparés par espaces) : "
read line; [[ -z "$line" ]] && { echo "❌ Aucun motif."; return; }
read -r -a patterns <<< "$line"
echo -n "🧹 Voulez-vous ignorer des dossiers ? (laisser vide si non) : "
read ignores
echo -n "📄 Nom du fichier de sortie (défaut: concat.txt) : "
read outfile; [[ -z "$outfile" ]] && outfile="concat.txt"
_concat_files "$ignores" "$outfile" "${patterns[@]}"
;;
4)
github
;;
5)
echo "👋 Bye"
;;
*)
echo "❌ Choix invalide: $1"
;;
esac
}
echo "🧰 Menu TOOLS"
echo "1) Afficher l'arborescence (structure.txt)"
echo "2) Lister les fichiers (filtres: types + globs)"
echo "3) Concaténer (filtres: types + globs)"
echo "4) Menu GitHub"
echo "5) Quitter"
echo -n "Ton choix : "
read raw
for choice in $(echo "$raw" | tr ',+' ' '); do run_choice "$choice"; done
}
# Menu GitHub (à adapter à tes chemins)
github() {
echo "🐙 Menu GitHub CLI"
echo "1) Créer un repo"
echo "2) Supprimer un repo"
echo "3) Lister mes repos"
echo "4) Passer un repo en public"
echo "5) Tout passer en privé"
echo "6) Changer visibilité d’un repo"
echo "7) Quitter"
echo -n "👉 Ton choix : "
read choice
case $choice in
1) bash ~/Documents/VisualStudioCode/dev-tools/github-tools/create-repo.sh ;;
2) bash ~/Documents/VisualStudioCode/dev-tools/github-tools/delete-repo.sh ;;
3) bash ~/Documents/VisualStudioCode/dev-tools/github-tools/list-repo.sh ;;
4) bash ~/Documents/VisualStudioCode/dev-tools/github-tools/make-public.sh ;;
5) bash ~/Documents/VisualStudioCode/dev-tools/github-tools/private-all.sh ;;
6) bash ~/Documents/VisualStudioCode/dev-tools/github-tools/togle-visibility.sh ;;
7) echo "👋 Retour" ;;
*) echo "❌ Choix invalide" ;;
esac
}
\n
===== ./bash-tools/get-structure.sh =====
#!/usr/bin/env bash
set -euo pipefail
# Structure arborescente
find . \( -path "./.git" -o -path "./node_modules" \) -prune -o -print \
| awk -F/ '{ indent=""; for(i=2;i<NF;i++) indent=indent"│ "; if(NF>1) print indent "├── " $NF; else print $0; }' \
> structure.txt
# Liste des .sh
find . \( -path "./.git" -o -path "./node_modules" \) -prune -o -type f -name "*.sh" -print > liste-sh.txt
\n
===== ./bash-tools/github.sh =====
#!/bin/bash
# ───────────────────────────────────────────────
# 📁 Menu GitHub CLI : github()
# 📌 Permet de lancer des actions GitHub depuis un menu
# ───────────────────────────────────────────────
set -euo pipefail
TOOLS_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
github() {
echo "🧰 Menu GitHub"
echo "1) Créer un repo"
echo "2) Supprimer un repo"
echo "3) Lister mes repos"
echo "4) Passer un repo en public"
echo "5) Tout passer en privé"
echo "6) Changer visibilité d’un repo"
echo "7) Quitter"
read -r -p "Ton choix : " choice
case "$choice" in
1) bash "$TOOLS_DIR/github-tools/create-repo.sh" ;;
2) bash "$TOOLS_DIR/github-tools/delete-repo.sh" ;;
3) bash "$TOOLS_DIR/github-tools/list-repo.sh" ;;
4) bash "$TOOLS_DIR/github-tools/make-public.sh" ;;
5) bash "$TOOLS_DIR/github-tools/private-all.sh" ;;
6) bash "$TOOLS_DIR/github-tools/toggle-visibility.sh" ;;
7) echo "👋 À bientôt" ;;
*) echo "❌ Choix invalide" ;;
esac
}
\n
===== ./github-tools/create-repo.sh =====
#!/usr/bin/env bash
set -euo pipefail
echo "🚀 Création d’un nouveau dépôt GitHub"
default_name="$(basename "$PWD")"
read -r -p "📝 Nom du dépôt [$default_name] : " repo_name
repo_name=${repo_name:-$default_name}
read -r -p "📄 Description du dépôt : " description
echo "🔐 Visibilité :"
select visibility in "public" "private"; do
[[ "$visibility" == "public" || "$visibility" == "private" ]] && break
echo "❌ Choix invalide."
done
# Init local si besoin
if ! git rev-parse --is-inside-work-tree >/dev/null 2>&1; then
git init
fi
if ! git rev-parse --verify HEAD >/dev/null 2>&1; then
git add -A
git commit -m "chore: initial commit"
fi
# Crée distante (sans casser si origin existe déjà)
if git remote get-url origin >/dev/null 2>&1; then
echo "ℹ️ Remote 'origin' existe déjà, je pousse simplement."
gh repo create "$repo_name" --"$visibility" --description "$description" --source=. --push || true
else
gh repo create "$repo_name" --"$visibility" --description "$description" --source=. --remote=origin --push
fi
echo "✅ Dépôt '$repo_name' prêt."
\n
===== ./github-tools/delete-repo.sh =====
#!/usr/bin/env bash
set -euo pipefail
echo "🗑️ Suppression d'un dépôt GitHub"
read -r -p "🔧 Nom du repo (ex: mon-repo ou wilonweb/mon-repo) : " INPUT
if [[ "$INPUT" == *"/"* ]]; then
REPO="$INPUT"
else
USERNAME="$(gh api user --jq .login)"
REPO="$USERNAME/$INPUT"
fi
echo "⚠️ Tu vas supprimer : $REPO (irréversible)"
read -r -p "✋ Confirmer ? (o/n) : " CONFIRM
[[ "$CONFIRM" == "o" ]] || { echo "❌ Annulé."; exit 1; }
gh repo delete "$REPO" --confirm
\n
===== ./github-tools/gh-sync.sh =====
#!/usr/bin/env bash
set -euo pipefail
# === Réglages ===
ROOT="${ROOT:-$HOME/Code}" # dossier où cloner/mettre à jour
USE_HTTPS="${GITHUB_USE_HTTPS:-0}"# 1 = utiliser HTTPS au lieu de SSH
DRY_RUN="${DRY_RUN:-0}" # 1 = ne fait qu'afficher les actions
need() { command -v "$1" >/dev/null 2>&1 || { echo "❌ $1 manquant"; exit 1; }; }
need gh; need git; mkdir -p "$ROOT"
# Détecte le login GitHub si possible
USERNAME="${USERNAME:-}"
if [[ -z "${USERNAME}" ]]; then
USERNAME="$(gh api user --jq .login 2>/dev/null || true)"
fi
if [[ -z "${USERNAME}" ]]; then
read -rp "GitHub username: " USERNAME
fi
echo "🔍 Quel type de dépôts veux-tu SYNC ?"
echo "1) Tous"
echo "2) Publics"
echo "3) Privés"
echo "4) Templates"
read -rp "#? " choice
case "$choice" in
1) FILTER='true' ;;
2) FILTER='.visibility=="public"' ;;
3) FILTER='.visibility=="private"' ;;
4) FILTER='.isTemplate==true' ;;
*) echo "❌ Choix invalide"; exit 1 ;;
esac
echo "📡 Récupération de la liste des dépôts de $USERNAME…"
# Pas besoin de jq installé : --jq est intégré à gh
REPOS="$(gh repo list "$USERNAME" --limit 200 \
--json name,sshUrl,url,visibility,isTemplate \
--jq ".[] | select($FILTER) | [.name,.sshUrl,.url] | @tsv")"
if [[ -z "$REPOS" ]]; then
echo "⚠️ Aucun dépôt trouvé pour ce filtre."; exit 0
fi
echo "📂 Dossier cible: $ROOT"
while IFS=$'\t' read -r NAME SSHURL HTTPSURL; do
[[ -n "$NAME" ]] || continue
DEST="$ROOT/$NAME"
REMOTE="$SSHURL"; [[ "$USE_HTTPS" = "1" ]] && REMOTE="$HTTPSURL"
if [[ ! -d "$DEST/.git" ]]; then
echo "📥 clone $NAME → $DEST"
[[ "$DRY_RUN" = "1" ]] || git clone "$REMOTE" "$DEST"
else
echo "🔄 sync $NAME"
(
cd "$DEST"
[[ "$DRY_RUN" = "1" ]] || git fetch -q
read -r A B <<<"$(git rev-list --left-right --count HEAD...@{u} 2>/dev/null || echo '0 0')"
STATUS="sync"
[[ "$B" != 0 && "$A" == 0 ]] && STATUS="pull"
[[ "$A" != 0 && "$B" == 0 ]] && STATUS="push"
[[ "$A" != 0 && "$B" != 0 ]] && STATUS="diverged"
echo " → $STATUS (ahead:$A behind:$B)"
if [[ "$DRY_RUN" != "1" && "$B" != 0 ]]; then git pull --ff-only || true; fi
)
fi
done <<< "$REPOS"
echo "✅ Terminé."
\n
===== ./github-tools/list-repo.sh =====
#!/usr/bin/env bash
set -euo pipefail
USERNAME="${USERNAME:-wilonweb}"
echo "🔍 Quel type de dépôts veux-tu afficher ?"
echo "1) Tous"
echo "2) Publics"
echo "3) Privés"
echo "4) Templates"
read -r -p "#? " choice
case "$choice" in
1) gh repo list "$USERNAME" --limit 200 ;;
2) gh repo list "$USERNAME" --visibility public --limit 200 ;;
3) gh repo list "$USERNAME" --visibility private --limit 200 ;;
4) gh repo list "$USERNAME" --limit 200 --json name,isTemplate,visibility \
--jq '.[] | select(.isTemplate==true) | "\(.visibility | ascii_upcase) - \(.name)"' ;;
*) echo "❌ Choix invalide"; exit 1 ;;
esac
\n
===== ./github-tools/liste-template.sh =====
#!/usr/bin/env bash
set -euo pipefail
USERNAME="${USERNAME:-wilonweb}"
gh repo list "$USERNAME" --limit 200 --json name,isTemplate,visibility \
--jq '.[] | select(.isTemplate==true) | "\(.visibility | ascii_upcase) - \(.name)"'
\n
===== ./github-tools/make-public.sh =====
#!/usr/bin/env bash
set -euo pipefail
echo "🔓 Passage d’un dépôt GitHub en public"
read -r -p "Nom du dépôt (ex: mon-repo) : " repo
USERNAME="${USERNAME:-$(gh api user --jq .login)}"
echo "🚀 $USERNAME/$repo → public…"
gh repo edit "$USERNAME/$repo" --visibility public --accept-visibility-change-consequences \
&& echo "✅ OK" || echo "❌ Erreur"
\n
===== ./github-tools/private-all.sh =====
#!/usr/bin/env bash
set -euo pipefail
USERNAME="${USERNAME:-$(gh api user --jq .login)}"
echo "⚠️ Tu vas rendre PRIVÉS tous les repos PUBLICS de $USERNAME"
read -r -p "Confirmer ? (tape: OUI) : " ok
[[ "$ok" == "OUI" ]] || { echo "❌ Annulé."; exit 1; }
gh repo list "$USERNAME" --limit 200 --json name,visibility --jq '.[] | select(.visibility=="public") | .name' \
| while read -r repo; do
echo "➡️ $repo → private"
gh repo edit "$USERNAME/$repo" --visibility private
done
echo "✅ Terminé."
\n
===== ./github-tools/toggle-visibility.sh =====
#!/usr/bin/env bash
set -euo pipefail
read -r -p "🔧 Repo (ex: wilonweb/mon-repo ou mon-repo) : " REPO
read -r -p "🎯 Nouvelle visibilité (public/private) : " VISIBILITY
[[ "$VISIBILITY" == "public" || "$VISIBILITY" == "private" ]] || { echo "❌ Visibilité invalide."; exit 1; }
if [[ "$REPO" != */* ]]; then
USERNAME="${USERNAME:-$(gh api user --jq .login)}"
REPO="$USERNAME/$REPO"
fi
echo "⚠️ $REPO → $VISIBILITY"
read -r -p "Confirmer ? (o/n) : " CONFIRM
[[ "$CONFIRM" == "o" ]] || { echo "❌ Annulé."; exit 1; }
gh repo edit "$REPO" --visibility "$VISIBILITY" --accept-visibility-change-consequences \
&& echo "✅ OK" || echo "❌ Échec"
\n
===== ./nodejs-update.sh =====
# === update-node-wsl.sh ===
set -e
# 1) Pré-requis
sudo apt-get update -y
sudo apt-get install -y curl ca-certificates
# 2) Installer/mettre à jour nvm
export NVM_DIR="$HOME/.nvm"
if [ ! -d "$NVM_DIR" ]; then
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
else
echo "nvm déjà présent dans $NVM_DIR"
fi
# 3) Charger nvm dans ce shell
export NVM_DIR="$HOME/.nvm"
# shellcheck disable=SC1090
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"
# 4) Installer Node LTS et le définir par défaut
nvm install --lts
nvm alias default lts/*
nvm use default
# 5) Afficher les versions
echo "✅ Versions actives :"
node -v
npm -v
\n