bcicen / slackcat

CLI utility to post files and command output to slack
http://slackcat.chat
MIT License
1.22k stars 57 forks source link

CLI argument to allow file type specification #18

Closed geoff-kruss closed 8 years ago

geoff-kruss commented 8 years ago

It would be nice to be able to tell slackcat what type of file you are uploading.

https://api.slack.com/methods/files.upload

Based on the documentation at the above link, specifically the filetype argument in the api call, I can't imagine this being too difficult to do. Currently, it seems to me as if all files are uploaded in a manner that makes slack treat the file as binary data. Initially it could be another argument on the command line and later you could think of adding file type detection (something simple, perhaps based on simple file extension)

screen shot 2016-01-11 at 3 05 35 pm

I'd like to contribute - If you agree that this is something that could be added i'll happily work on it.

bcicen commented 8 years ago

Good point @geoff-kruss; have you tried using a filename with a specific extension? e.g slackcat -c my-channel -f test.py does accurately provide python syntax highlighting. Maybe there's a use case for overriding with a given filetype?

geoff-kruss commented 8 years ago

@bcicen take this use case: cat x.py | slackcat -c channel - it would be nice to be able to tell slackcat the incoming data via stdin is python code and have it force the fomatting. What do you think?

So ultimately we land up with something like this: cat x.py | slackcat -c channel -f python or equivalent

bcicen commented 8 years ago

That functionality is already there, as Slack will try to auto-identify by file extension and content. If you try cat x.py | slackcat -c channel -n example.py(-n opt is used to specify the file name in Slack), you'll see the resulting upload does have python syntax highlighting.

geoff-kruss commented 8 years ago

@bcicen great, thank you. I should have checked this out myself before commenting. My apologies. There is another interesting use case here however which might still make adding an explicit type override valuable:

ls | slackcat -c channel

The above will upload a file (named by timestamp) as a binary file. To be quite honest I don't have a suggestion on how best to fix that, but terminal output being uploaded as binary means that the UI in slack doesn't render the content, but instead renders it as per my image above.

Please excuse my ignorance, but is there a current workaround for forcing this to be rendered as plain text? If not, this idea may still have legs. If there is a workaround, I won't continue this thread. I think #20 might be referring to the same use case as well.

bcicen commented 8 years ago

It seems that Slack is probably detected the file as binary due to some colored text in your ls output, which gets uploaded looking like: ^[[0m^[[01;32mfile.txt^[[0m. You likely have an alias for ls that adds color(check alias | grep ls), so try running

/bin/ls | slackcat -c channel

Without the --color option, the file snippet is displayed/previewed in plaintext in Slack.

(fyi, I had a type above -- the option switch for filename is actually -n, not -f)