1
0
mirror of https://github.com/nvbn/thefuck.git synced 2025-02-07 13:41:21 +00:00

#330 Add support of a single argument

This commit is contained in:
nvbn 2015-08-09 22:55:48 +03:00
parent 215c64d924
commit 6222985491
2 changed files with 36 additions and 6 deletions

View File

@ -107,9 +107,9 @@ sudo pip install thefuck
You should place this command in your `.bash_profile`, `.bashrc`, `.zshrc` or other startup script: You should place this command in your `.bash_profile`, `.bashrc`, `.zshrc` or other startup script:
```bash ```bash
eval "$(thefuck-alias)" eval "$(thefuck --alias)"
# You can use whatever you want as an alias, like for Mondays: # You can use whatever you want as an alias, like for Mondays:
eval "$(thefuck-alias FUCK)" eval "$(thefuck --alias FUCK)"
``` ```
[Or in your shell config (Bash, Zsh, Fish, Powershell, tcsh).](https://github.com/nvbn/thefuck/wiki/Shell-aliases) [Or in your shell config (Bash, Zsh, Fish, Powershell, tcsh).](https://github.com/nvbn/thefuck/wiki/Shell-aliases)

View File

@ -1,6 +1,9 @@
from argparse import ArgumentParser
from warnings import warn
from pathlib import Path from pathlib import Path
from os.path import expanduser from os.path import expanduser
from pprint import pformat from pprint import pformat
import pkg_resources
from subprocess import Popen, PIPE from subprocess import Popen, PIPE
import os import os
import sys import sys
@ -80,7 +83,7 @@ def run_command(command, settings):
# Entry points: # Entry points:
def main(): def fix_command():
colorama.init() colorama.init()
user_dir = setup_user_dir() user_dir = setup_user_dir()
settings = conf.get_settings(user_dir) settings = conf.get_settings(user_dir)
@ -94,8 +97,35 @@ def main():
run_command(selected_command, settings) run_command(selected_command, settings)
def print_alias(): def print_alias(entry_point=True):
if entry_point:
warn('`thefuck-alias` is deprecated, us `thefuck --alias` instead.')
position = 1
else:
position = 2
alias = shells.thefuck_alias() alias = shells.thefuck_alias()
if len(sys.argv) > 1: if len(sys.argv) > position:
alias = sys.argv[1] alias = sys.argv[position]
print(shells.app_alias(alias)) print(shells.app_alias(alias))
def main():
parser = ArgumentParser(prog='The Fuck')
parser.add_argument('-v', '--version',
action='version',
version='%(prog)s {}'.format(
pkg_resources.require('thefuck')[0].version))
parser.add_argument('-a', '--alias',
action='store_true',
help='[custom-alias-name] prints alias for current shell')
parser.add_argument('command',
nargs='*',
help='command that should be fixed')
known_args = parser.parse_args(sys.argv[1:2])
if known_args.alias:
print_alias(False)
elif known_args.command:
fix_command()
else:
parser.print_usage()