Selaa lähdekoodia

Making language_chooser.sh create source code

Vinicius Teshima 1 kuukausi sitten
vanhempi
sitoutus
67623bba84
1 muutettua tiedostoa jossa 17 lisäystä ja 1 poistoa
  1. 17 1
      language_chooser.sh

+ 17 - 1
language_chooser.sh

@@ -12,6 +12,9 @@
 #
 #echo "$languages" | shuf | head -n5
 
+prob="$1"
+test -n "$prob" || { echo "Pass the problem number"; exit 1;}
+
 lang_frek="$(find . -maxdepth 1 -mindepth 1 -not -path './.git' -type d \
     | parallel -j1 'find {} -maxdepth 1 -mindepth 1 -type f | wc -l | xargs echo {}' \
     | sort -k2)"
@@ -20,4 +23,17 @@ lest_amount="$(echo "$lang_frek" | head -n1 | cut -d' ' -f2)"
 
 possibles="$(echo "$lang_frek" | grep "$lest_amount" | sed "s/ ${lest_amount}//g")"
 
-echo "$possibles" | shuf | head -n5
+chosen="$(echo "$possibles" | shuf | head -n1)"
+
+newest_file="$(find "${chosen}" -type f -printf "%T@ %p\n" \
+                 | sort -n \
+                 | cut -d' ' -f 2- \
+                 | tail -n 1)"
+
+bn="$(basename "$newest_file")"
+ext="$(echo "$bn" | cut -d'.' -f2)"
+
+cp "$newest_file" "${chosen}/${prob}.${ext}"
+
+echo "Language ${chosen}"
+echo "File: '${chosen}/${prob}.${ext}'"