thefuck icon indicating copy to clipboard operation
thefuck copied to clipboard

Add instructions to use in corporate environment

Open mensly opened this issue 4 years ago • 4 comments

thefuck is extremely useful for developers and other professions that might require using, for example, a locked down Macbook that does not have local administrator access. I think it is important to include some instructions on how to get the tool set up in such an environment because it may not be obvious but fairly straightforward if you know what you're doing.

By the way, since I use it as an example, I got fish installed without admin access too:

ln -s ~/Applications/fish.app/Contents/Resources/base/usr/local/bin/fish ~/bin/fish

Fixes #1252

mensly avatar Dec 14 '21 00:12 mensly

I think a cleaner way than using thedang --alias | sed .. would be to just specify the alias to be dang:

user@ubuntu:~$ for x in ~/.local/bin/{fuck,thefuck}; do ln -vs "$x" "${x%fuck}dang"; done
'/home/user/.local/bin/dang' -> '/home/user/.local/bin/fuck'
'/home/user/.local/bin/thedang' -> '/home/user/.local/bin/thefuck'
user@ubuntu:~$ thedang --alias dang

            function dang () {
                TF_PYTHONIOENCODING=$PYTHONIOENCODING;
                export TF_SHELL=bash;
                export TF_ALIAS=dang;
                export TF_SHELL_ALIASES=$(alias);
                export TF_HISTORY=$(fc -ln -10);
                export PYTHONIOENCODING=utf-8;
                TF_CMD=$(
                    thefuck THEFUCK_ARGUMENT_PLACEHOLDER "$@"
                ) && eval "$TF_CMD";
                unset TF_HISTORY;
                export PYTHONIOENCODING=$TF_PYTHONIOENCODING;
                history -s $TF_CMD;
            }
        
user@ubuntu:~$ 

No need for sed. If you want you could use the above for the instructions for Bash.

rany2 avatar Dec 21 '21 16:12 rany2

@rany2 The --alias argument only changes the name of the alias to type in, not the script that alias is calling. Take a look at TF_CMD in your example. This would've worked for you because thefuck is also in your $PATH, if someone has set this up as thedang instead of thefuck it would not work. sed will change both to remove the word "fuck".

mensly avatar Dec 21 '21 22:12 mensly

@mensly Sorry I didn't notice. I get why you did it now but I am not sure if sed might unintentionally break something in the future. Might be better to just add an option that allows you to set a custom thefuck.

Edit: also I noticed that if you just run dang and you didn't make any mistakes it will still return No fucks given.

rany2 avatar Dec 21 '21 22:12 rany2

This PR is intended only to document how the current product can be installed and used in a corporate environment, I like the idea of that option you spoke of though I think an alternative would be for the script name thefuck to be replaced with whatever the current command is that called thefuck --alias. Python isn't my main language, but I think sys.argv[0] has this string. I might experiment with this and if it proves useful do another PR after this one is merged.

I faced a lot of technical issues when I was trying to get this working myself and wanted to help others have an easier time. My current employer is actually ok with some casual swearing if it isn't used to hurt people, but I didn't know that when I was getting my computer set up which is why I set it up as dang. My example of configuring for fish is only an example of what is described in the previous paragraph. For a user without admin privileges that doesn't give a fuck about swearing, the configuration is a lot simpler and identical to that in the README already, ie adding eval $(thefuck --alias) to .bashrc. I'll add an extra sentence clarifying this.

As for outputting 'No fucks given', modifying the behaviour of the code will depend more on someone's environment. As this is something I haven't needed to do I can't tell you the best solution but I can imagine you could either edit your local copy of the .py file this string is contained in, or modifying the alias to edit stdout:

TF_CMD=$(
    thedang THEFUCK_ARGUMENT_PLACEHOLDER "$@" 2>&1 | sed 's/fuck/dang/'
) && eval "$TF_CMD";

A command line argument to set the error message (both when aliasing and evaluating) would be a better solution, so I might also look into that in the future PR I mentioned. To reiterate, I wanted to document what I needed to do to get the current version working on a corporate-controlled computer but am interested in modifying the software. I have another project I'm focused on at the moment, but worst case scenario this is MIT licensed so I can always publish to PyPI under the name thedang just to make it easier for people like me to use their preferred tools in their day job.

mensly avatar Dec 21 '21 22:12 mensly

Wiki is the place for that.

scorphus avatar Aug 31 '22 18:08 scorphus