Dear Fish users,
For those who are interested, the following Python scripts implement the
commands "alias2" and "unalias2". They may be saved as "/usr/bin/alias2" and
"/usr/bin/unalias2", although saving them anywhere else on $PATH will do as
well. The scripts have not been optimized. They have not been tested either.
So, use them at your own risk.
Best wishes,
Guido van Steen
"""#!/usr/bin/env python
# save this script as "/usr/bin/alias2" and make it executable
import os
import sys
id_string = "#This file was created by alias2. Do not edit it. It may be
overwritten automatically."
config_file = ".config/alias2/alias2.config"
home = os.getenv("HOME")
path = os.getenv("PATH")
if home + "/bin" not in path:
print "alias2: \"" + home + "/bin\" required to be in the $PATH
environment variable "
sys.exit(2)
alias_cmd = ""
for i in range(len(sys.argv)):
if i != 0:
alias_cmd = alias_cmd + sys.argv[i] + " "
alias = alias_cmd.split("=")[0].strip()
try:
aliased = alias_cmd.split("=")[1].strip()
except IndexError:
## to be done later:
# if (len(sys.argv) == 2):
# print_the_contents_of_alias2_config()
# if (len(sys.argv) == 3):
# if sys.argv[3] == "-a"
# print_the_contents_of_alias2_config()
print "alias2: no equal sign in \"alias2 " + alias_cmd.strip() + "\"."
sys.exit(2)
if not alias.replace("-","").isalnum():
print "alias2: \"" + alias + "\" contains one or more awkward
characters "
sys.exit(2)
if alias.split(" ")[0] != alias:
print "alias2: " + alias + " cannot be alias2ed."
sys.exit(2)
if os.path.exists(home + "/bin/" + alias):
fhr = open(home + "/bin/" + alias, "r")
contents = fhr.read()
fhr.close()
if not id_string in contents:
print "alias2: " + home + "/bin/" + alias + " exists. Remove it
manually. "
sys.exit(2)
fhw = open(home + "/bin/" + alias, "w")
fhw.write("#!/bin/bash \n\n")
fhw.write(id_string + "\n\n")
fhw.write(aliased + ' "$@"' + " \n")
fhw.close()
os.system("chmod +x " + home + "/bin/" + alias)
print "alias2: " + alias + " created as an alias2 script"
if not os.path.exists(home + "/" + os.path.dirname(config_file)):
dir_list = os.path.dirname(config_file).split("/")
dir_processed = home
for i in dir_list:
dir_processed = dir_processed + "/" + i
try:
os.mkdir(dir_processed)
except OSError:
pass
try:
fhr = open(home + "/" + config_file, "r")
contents = fhr.read()
fhr.close()
except IOError:
contents = ""
line_by_line = contents.split("\n")
already_registered = 0
for i in line_by_line:
if alias == i:
already_registered = 1
if not already_registered:
fhw = open(home + "/" + config_file, "w")
fhw.write(contents + alias + "\n")
fhw.close()
"""
"""#!/usr/bin/env python
# save this script as "/usr/bin/unalias2" and make it executable
import os
import sys
dir_name = os.path.dirname(__file__)
fhr = open(dir_name + "/alias2")
contents = fhr.read()
id_string = contents.split("id_string")[1].split('"')[1].split('"')[0]
config_file = contents.split("config_file")[1].split('"')[1].split('"')[0]
fhr.close()
home = os.getenv("HOME")
if (len(sys.argv) != 2) :
print "unalias2: provide one argument exactly"
sys.exit(2)
to_be_unaliased = sys.argv[1]
if os.path.exists(home + "/bin/" + to_be_unaliased):
fhr = open(home + "/bin/" + to_be_unaliased, "r")
contents = fhr.read()
fhr.close()
if not id_string in contents:
print "unalias2: " + home + "/bin/" + to_be_unaliased + " was
not created by alias2. Remove it manually"
sys.exit(2)
else:
os.remove(home + "/bin/" + to_be_unaliased)
print "unalias2: " + home + "/bin/" + to_be_unaliased + "
removed"
else:
print "unalias2: " + home + "/bin/" + to_be_unaliased + " does not
exist"
sys.exit(2)
fhr = open(home + "/" + config_file , "r")
contents = fhr.read().replace(to_be_unaliased + "\n","")
fhr.close()
fhw = open(home + "/" + config_file, "w")
fhw.write(contents)
fhw.close()
"""
--- On Thu, 8/7/08, Isaac Dupree <[EMAIL PROTECTED]> wrote:
> From: Isaac Dupree <[EMAIL PROTECTED]>
> Subject: Re: [Fish-users] Problem with sudo and Fish functions
> To: "Martin Bähr" <[EMAIL PROTECTED]>
> Cc: [EMAIL PROTECTED], [email protected]
> Date: Thursday, August 7, 2008, 3:47 PM
> Martin Bähr wrote:
> > On Thu, Aug 07, 2008 at 05:30:37AM -0700,
> [EMAIL PROTECTED] wrote:
> >> [EMAIL PROTECTED] ~> sudo agi install fish
> >> sudo: agi: command not found
> >
> > did you set up fish as a root shell?
> > if not, this can't work, because sudo will be
> calling bash and that
> > won't have agi defined.
>
> sudo doesn't even call bash. It just searches $PATH
> (maybe
> even a sanitized $PATH). Your non-root shell has already
> done the argument parsing. Decent workarounds include
> putting a script in $PATH ... either try somewhere in your
> $HOME or use /usr/local/bin or something. E.g.
> > cat /usr/local/bin/agi
> #!/bin/sh
> apt-get install "$@"
>
> > #don't forget to chmod +x path/to/script
>
> -Isaac
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Fish-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/fish-users