From 5fa4dd1b8ca62759f420df42a7379f77561f6e1c Mon Sep 17 00:00:00 2001 From: "Fred T. Hamster" Date: Wed, 16 Apr 2025 09:02:22 -0400 Subject: [PATCH] more plowing through the python --- scripts/core/generate_aliases-new.py | 79 ++++++++++++++++++---------- 1 file changed, 51 insertions(+), 28 deletions(-) diff --git a/scripts/core/generate_aliases-new.py b/scripts/core/generate_aliases-new.py index bbb1db55..3fc8e386 100644 --- a/scripts/core/generate_aliases-new.py +++ b/scripts/core/generate_aliases-new.py @@ -38,8 +38,7 @@ FEISTY_MEOW_LOADING_DOCK = os.environ['FEISTY_MEOW_LOADING_DOCK'] FEISTY_MEOW_SCRIPTS = os.environ['FEISTY_MEOW_SCRIPTS'] DEBUG_FEISTY_MEOW = os.environ['DEBUG_FEISTY_MEOW'] -print("home is $HOME") - +print("home is " + HOME) print("bailing now...") @@ -47,7 +46,6 @@ exit(1) -#hmmm: unscanned after here... there be monsters. @@ -55,37 +53,62 @@ exit(1) # or bash alias for it. it needs the filename of the possible alias and the # directory where that file resides. def make_alias(file: str, dir: str) -> None: + # we'll set the shorter alias name if we find a match for the file extension. + aliasname = None + + alias_handling_methods = {'py':'make_python_alias', 'sh':'make_bash_alias', 'pl':'make_perl_alias'} + +#done#hmmm: could have better connection between our list of methods and the extensions, so we actually use +## the extension to chop up the file name and then invoke the right function. + + for extension, method in alias_handling_methods.items(): + found = re.search("^.*\." + extension, file, re.IGNORECASE) + if found: + aliasname = re.sub("^.*\." + extension, "", file, re.IGNORECASE) + funky = method + break + +# funky = None +# # python scripts with '.py'. +# found = re.search("^.*\.[pP][yY]", file) +# if found: +# aliasname = re.sub("\.[pP][yY]", "", file) +# funky = alias_handling_methods['py'] +# # bash scripts with '.sh'. +# found = re.search("^.*\.[sS][hH]", file) +# if found: +# aliasname = re.sub("\.[sS][hH]", "", file) +# funky = alias_handling_methods['sh'] +# # perl scripts with '.pl'. +# found = re.search("^.*\.[pP][lL]", file) +# if found: +# aliasname = re.sub("\.[pP][lL]", "", file) +# funky = alias_handling_methods['pl'] + + if aliasname is not None: + print("aliasname is " + aliasname + " and funky is " + funky) + # evaluate a function call with the chosen method. + eval(funky+'(' + aliasname + ',' + dir + ')'); + else: + print("could not find a matching extension for the file: ' + file) - found = re.search("^.*\.[pP][yY]", file) - if found: - aliasname = re.sub("\.[pP][Yy]", "", file) - print("aliasname is " + aliasname) - make_python_alias(aliasname, "$dir"); - - found = re.search("^.*\.[sS][hH]", file) - if found: -blah - - - } elsif ($file =~ /\.[sS][hH]$/) { - local($aliasname) = $file; $aliasname =~ s/\.[Ss][Hh]$//; - &make_bash_alias($aliasname, "$dir"); - } elsif ($file =~ /\.[pP][lL]$/) { - local($aliasname) = $file; $aliasname =~ s/\.[Pp][lL]$//; - &make_perl_alias($aliasname, "$dir"); - } -} +#### # makes an alias for a bash script given the alias name. -sub make_bash_alias { - local($aliasname) = shift(@_); - local($full_alias) = $aliasname; -#print "full alias is $full_alias\n"; - $aliasname =~ s/^.*\/([^\/]*)/\1/; -#print "alias became $aliasname\n"; +def make_bash_alias(aliasname: str, dir: str) -> str: + full_alias = aliasname + print "full alias is " + full_alias + aliasname = re.sub(r'^.*/([^/]*)', r'\1') +# $aliasname =~ s/^.*\/([^\/]*)/\1/; + print "alias became: " + aliasname +#not ready here yet print she "define_yeti_alias $aliasname=\"bash $full_alias.sh\"\n"; } +#hmmm: unscanned after here... there be monsters. + + + # makes an alias for a python script given the alias name. #hmmm: don't love that we're hardcoding python3 in here, but apparently some systems don't have a 'python' command despite having python installed. sub make_python_alias { -- 2.34.1