mirror of
https://github.com/benapetr/stikkit.git
synced 2025-04-25 20:41:20 -05:00
Compare commits
10 Commits
Release_1.
...
master
Author | SHA1 | Date | |
---|---|---|---|
|
d9f75dc9d4 | ||
|
3160b2f25f | ||
|
7d0ad8b550 | ||
|
885c4f441c | ||
|
950094775c | ||
efbdaa0c6d | |||
|
dcba663d8d | ||
|
d65aee1cbf | ||
|
c2aa1ca3d1 | ||
|
14ad63ba98 |
21
README.md
21
README.md
@ -31,14 +31,16 @@ Checkout this repository
|
||||
cd stikkit
|
||||
cmake .
|
||||
make
|
||||
make install
|
||||
sudo make install
|
||||
```
|
||||
|
||||
NOTE: you need to have libcurl-dev installed in your system
|
||||
NOTE: you need to have `libcurl-dev` installed in your system
|
||||
|
||||
Usage
|
||||
=====
|
||||
|
||||
See `stikkit --help` for detailed help about options.
|
||||
|
||||
```
|
||||
stikkit -b url
|
||||
# now type text and hit ctrl+d to exit
|
||||
@ -50,9 +52,22 @@ url is an url to stikked server for example, if your server is http://something.
|
||||
|
||||
The url parameter can be stored to configuration file (stikkit will ask you in case there is none in config file)
|
||||
|
||||
Configuration
|
||||
=====
|
||||
|
||||
The default configuration pulls the URL from `/etc/stikkit/url` - however, the better approach is to create your own config directory.
|
||||
|
||||
The stikkit software will look for `.stikkit` in your home directory. Within this directory, there are a few key files worth creating.
|
||||
|
||||
- *url* - Contains your base installation URL for stikked
|
||||
- *apikey* - If your stikked installation requires an API key, save it in here
|
||||
- *expiry* - The default expiry time (in minutes) for a paste, if needed
|
||||
- *author* - The default author name if you wish to use one
|
||||
- *private* - If you want to mark the paste as private (not visible in recent pastes), create this empty file
|
||||
|
||||
Tips
|
||||
=====
|
||||
|
||||
Do you have a server and want to setup default pastebin site for all users in system?
|
||||
|
||||
Create /etc/stikkit/url which contains the url of default pastebin site. Users will be able to override it, but by default everyone on system will use this
|
||||
Create `/etc/stikkit/url` which contains the url of default pastebin site. Users will be able to override it, but by default everyone on system will use this
|
||||
|
@ -30,6 +30,8 @@ string Configuration::Home = "";
|
||||
bool Configuration::NoExtras = false;
|
||||
string Configuration::Input = "";
|
||||
string Configuration::DefaultURL = "";
|
||||
string Configuration::Apikey = "";
|
||||
string Configuration::Lang = "";
|
||||
|
||||
void Configuration::Init()
|
||||
{
|
||||
@ -48,6 +50,17 @@ void Configuration::Init()
|
||||
}
|
||||
f.close();
|
||||
}
|
||||
if (stat("/etc/stikkit/apikey", &st) != -1)
|
||||
{
|
||||
ifstream f;
|
||||
f.open("/etc/stikkit/apikey");
|
||||
string line;
|
||||
if (getline(f, line))
|
||||
{
|
||||
Configuration::Apikey = line;
|
||||
}
|
||||
f.close();
|
||||
}
|
||||
if (stat(string(homedir + "/.stikkit").c_str(), &st) == -1)
|
||||
{
|
||||
mkdir(string(homedir + "/.stikkit").c_str(), 0750);
|
||||
@ -61,6 +74,53 @@ void Configuration::Init()
|
||||
Configuration::DefaultURL = line;
|
||||
}
|
||||
f.close();
|
||||
|
||||
//Apikey
|
||||
ifstream fapi;
|
||||
fapi.open(string(homedir + "/.stikkit/apikey").c_str());
|
||||
string lineapi;
|
||||
if(getline(fapi, lineapi))
|
||||
{
|
||||
Configuration::Apikey = lineapi;
|
||||
}
|
||||
fapi.close();
|
||||
|
||||
//Lang
|
||||
ifstream flang;
|
||||
flang.open(string(homedir + "/.stikkit/lang").c_str());
|
||||
string linelang;
|
||||
if(getline(flang, linelang))
|
||||
{
|
||||
Configuration::Lang = linelang;
|
||||
}
|
||||
flang.close();
|
||||
|
||||
//expiry
|
||||
ifstream fexp;
|
||||
fexp.open(string(homedir + "/.stikkit/expiry").c_str());
|
||||
string lineexp;
|
||||
if(getline(fexp, lineexp))
|
||||
{
|
||||
Configuration::Expiry = lineexp;
|
||||
}
|
||||
fexp.close();
|
||||
|
||||
//author
|
||||
ifstream fauth;
|
||||
fauth.open(string(homedir + "/.stikkit/author").c_str());
|
||||
string lineauth;
|
||||
if(getline(fauth, lineauth))
|
||||
{
|
||||
Configuration::Author = lineauth;
|
||||
}
|
||||
fauth.close();
|
||||
|
||||
//private
|
||||
std::ifstream fpriv(homedir + "/.stikkit/private");
|
||||
if(fpriv.good())
|
||||
{
|
||||
Configuration::Private = true;
|
||||
}
|
||||
}
|
||||
if (Configuration::Author.length() < 1)
|
||||
{
|
||||
|
@ -33,6 +33,8 @@ namespace Stikkit
|
||||
static string DefaultURL;
|
||||
static bool Private;
|
||||
static string Home;
|
||||
static string Apikey;
|
||||
static string Lang;
|
||||
static bool NoExtras;
|
||||
};
|
||||
}
|
||||
|
@ -103,6 +103,18 @@ int main(int argc, char *argv[])
|
||||
readBuffer.clear();
|
||||
string post = "text=";
|
||||
post += curl_easy_escape(curl, Stikkit::Configuration::Source.c_str(), Stikkit::Configuration::Source.length());
|
||||
if (Stikkit::Configuration::Apikey.length() > 0)
|
||||
{
|
||||
Stikkit::Configuration::URL += "?apikey=";
|
||||
Stikkit::Configuration::URL += curl_easy_escape(curl, Stikkit::Configuration::Apikey.c_str(), Stikkit::Configuration::Apikey.length());
|
||||
}
|
||||
|
||||
if (Stikkit::Configuration::Lang.length() > 0)
|
||||
{
|
||||
post += "&lang=";
|
||||
post += curl_easy_escape(curl, Stikkit::Configuration::Lang.c_str(), Stikkit::Configuration::Lang.length());
|
||||
}
|
||||
|
||||
if (Stikkit::Configuration::Author.length() > 0)
|
||||
{
|
||||
post += "&name=";
|
||||
@ -117,14 +129,17 @@ int main(int argc, char *argv[])
|
||||
post += "&private=1";
|
||||
if (Stikkit::Configuration::Expiry != "0")
|
||||
post += "&expire=" + Stikkit::Configuration::Expiry;
|
||||
string useragent;
|
||||
useragent = "Stikkit " + Stikkit::Configuration::Version + " (https://github.com/benapetr/stikkit/)";
|
||||
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback);
|
||||
curl_easy_setopt(curl, CURLOPT_URL, Stikkit::Configuration::URL.c_str());
|
||||
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, post.c_str());
|
||||
curl_easy_setopt(curl, CURLOPT_USERAGENT, "stikkit");
|
||||
curl_easy_setopt(curl, CURLOPT_USERAGENT, useragent.c_str());
|
||||
|
||||
/* Perform the request, res will get the return code */
|
||||
/* Perform the request, res will get the return HTTP code */
|
||||
res = curl_easy_perform(curl);
|
||||
/* Check for errors */
|
||||
cerr << "\n";
|
||||
if(res != CURLE_OK)
|
||||
{
|
||||
cerr << "curl_easy_perform() failed: " << curl_easy_strerror(res) << endl;
|
||||
|
@ -95,6 +95,28 @@ bool TerminalParser::Parse()
|
||||
cerr << "Parameter -i requires an argument for it to work!" << endl;
|
||||
return true;
|
||||
}
|
||||
} else if (text.at(0) == 'k')
|
||||
{
|
||||
if (this->argc > x + 1 && !this->argv[x + 1][0] != '-')
|
||||
{
|
||||
x++;
|
||||
Configuration::Apikey = this->argv[x];
|
||||
} else
|
||||
{
|
||||
cerr << "Parameter -k requires an argument for it to work!" << endl;
|
||||
return true;
|
||||
}
|
||||
} else if (text.at(0) == 'l')
|
||||
{
|
||||
if (this->argc > x + 1 && !this->argv[x + 1][0] != '-')
|
||||
{
|
||||
x++;
|
||||
Configuration::Lang = this->argv[x];
|
||||
} else
|
||||
{
|
||||
cerr << "Parameter -l requires an argument for it to work!" << endl;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
text = text.substr(1);
|
||||
}
|
||||
@ -149,6 +171,8 @@ void TerminalParser::DisplayHelp()
|
||||
" -s: Display only RAW url of paste and no extra text\n"\
|
||||
" -e <minutes>: Set expiry in minutes, parameter needs\n"\
|
||||
" to be a number, default: unlimited time\n"\
|
||||
" -k <apikey>: Set api key for current server\n"\
|
||||
" -l <lang>: Set paste lang for syntax highlighting\n"\
|
||||
" --version: Display a version\n"\
|
||||
" -h | --help: Display this help\n\n"\
|
||||
"Note: every argument in [brackets] is optional\n"\
|
||||
|
Loading…
x
Reference in New Issue
Block a user